This release contains a number of fixes, enhancements and breaking changes.
The list of breaking changes can be found here
Extend all the SDL types
The graphql SDL specification has finally hit master at Facebook and graphql-java has reflected this.
https://github.com/facebook/graphql/blob/master/spec/Section%203%20--%20Type%20System.md
One new capability is that you can now extend all the different types not just Object types, which includes Interfaces, Unions, Enums, Scalars and Input Objects.
interface NamedEntity {
name: String
}
interface ValuedEntity {
value: Int
}
type Person implements NamedEntity {
name: String
age: Int
}
type Business implements NamedEntity & ValuedEntity {
name: String
value: Int
employeeCount: Int
}
extend interface NamedEntity {
nickname: String
}
extend type Person {
nickname: String
}
extend type Business {
nickname: String
}
See:
Directives on runtime types
You can specify directives during SDL type definition and these have now been captured and transferred to the graphql runtime types.
So for example given
type Person implements NamedEntity {
name: String
age: Int
wage : Int @security(role:"manager")
}
The special directive security
will be made available on the wage
field.
GraphQLDirective securityDirective = personType.getField("wage).getDirective("security")
See
Instrumentation
The graphql.execution.instrumentation.Instrumentation
SPI has been significantly changed. graphql-java uses an asynchronous model to execute a query and Instrumentation
and InstrumentationContext
has been changed to reflect that.
The signature of the methods have been changed to reflect that instrumentation callbacks now happen in two phases. The first is when the engine first dispatches an operation step and then again when it asynchronously completes.
public interface InstrumentationContext<T> {
/**
* This is invoked when the instrumentation step is initially dispatched
*
* @param result the result of the step as a completable future
*/
void onDispatched(CompletableFuture<T> result);
/**
* This is invoked when the instrumentation step is fully completed
*
* @param result the result of the step (which may be null)
* @param t this exception will be non null if an exception was thrown during the step
*/
void onCompleted(T result, Throwable t);
}
This is a breaking change to code that has implemented Instrumentation
. You will have to change the code to implement this double callback pattern.
See #894
@fetch directive has been added to SDL
You can now specify an alternative name to fetch property values from during SDL type declaration
type Invoice {
id : ID
invoiceDate : String @fetch(from:"whenInvoiced")
}
This allows indirection between the names you want to use in a graphql schema and the backing Java data
without having to write this mapping logic into all your data fetchers.
Experimental support for deferred execution
You can now support a deferred execution of parts of a query via @defer
directive.
(This is an experimental feature, it is currently not part of the official spec.)
The ability to have more than one error per field
The graphql spec is not super clear on whether multiple errors are allowed per field during execution. The previous code took the approach that they are not. However a re-interpretation of the specification reveals that is only true for null field checks.
So the restriction has been lifted and you can have multiple errors per field (except for null checks during execution)
See
#895
Performance improvements during type look up
Our friends from Intuit have contributed a series fo fix to help with the performance of the graphql-java engine during schema type look up, which happens a lot during the execution of a query.
See #898
graphql.execution.batched.BatchedExecutionStrategy has been deprecated
graphql.execution.batched.BatchedExecutionStrategy
has been deprecated as an execution strategy.
It does not follow the graphql specification correctly and it has challenges on deeply nested queries with stack overflows being possible. While it remains in the code base, it may be removed at a later time.
See : #965
Other changes and fixes
The rest of the PRs for 8.0 can be found by following this link
https://github.com/graphql-java/graphql-java/pulls?utf8=%E2%9C%93&q=is%3Apr+milestone%3A8.0+