Releases: graphql-java-kickstart/graphql-java-servlet
7.3.3
7.3.2
7.1.1
7.1.0
7.0.1
7.0.0
Updated graphql-java dependency to 11.0
Graphql-Java has been updated to 11.0, which contains breaking changes. See the release notes.
Simplified construction of GraphQL Servlet
The process for constructing a GraphQL Servlet has been simplified. If you just want to use all default settings and want to expose a schema you can simply create the servlet calling GraphQLHttpServlet.with(graphqlSchema)
.
If you need more control you can use GraphQLHttpServlet.with(graphqlConfiguration)
. The GraphQLConfiguration
can be built in line with how the Builder
worked before.
The third option is by subclassing the GraphQLHttpServlet
:
@WebServlet(name = "HelloServlet", urlPatterns = {"graphql"}, loadOnStartup = 1)
public class HelloServlet extends GraphQLHttpServlet {
@Override
protected GraphQLConfiguration getConfiguration() {
return GraphQLConfiguration.with(createSchema()).build();
}
private GraphQLSchema createSchema() {
String schema = "type Query{hello: String}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring()
.type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world")))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
}
}
Improved naming for getting files from GraphQLContext
The method GraphQLContext.getFiles()
incorrectly gave the impression it would only return Part
representing actual files, while it included other form fields as well. Therefore deprecated this method and added two alternatives:
/**
* @return list of all parts representing files
*/
public List<Part> getFileParts();
/**
* @return map representing all form fields
*/
public Map<String, List<Part>> getParts()
Fixed Karaf example
The Karaf example hadn't been updated in a while and therefore wouldn't run anymore. All dependencies have been updated now to work with the latest versions.
Improve schema OSGi whiteboard update performance by batching
Allow the ability to delay the update of the schema through a config option. By default this is 0, leaving the behaviour unchanged, and no penalty is paid. If the delay is set to a non zero value, it only updates the schema if no
changes to the whiteboard have happened within that delay timeout.
Also fixed up a couple of things with the whiteboard. Using policy=DYNAMIC
is the normal approach, the component can activate and gets references added as appropriate. The "typesProviders" method was in error as the name didn't match the unbind. I believe that what was happening before is that the component was being activated
and deactivated each time a new reference was added. Now it's activated once and the whiteboard works correctly.
It has been advised by the contributor @tomq42 to set the default delay to 150ms. This will give improved behaviour for most people. The default has been left though as 0 so that the current behaviour is maintained, and there is no impact of this change at all otherwise.
6.2.0
Breaking change: added HttpServletResponse to GraphQLContextBuilder
The HttpServletResponse
was inadvertently removed from GraphQLContext
and its related builders. To reinstate it we needed to add the field to multiple builders and the DefaultGraphQLContextBuilder
. This allows you to use the HttpServletResponse
in your custom GraphQLContextBuilder
now which was the purpose of this change.
This means implementations of GraphQLContextBuilder
need to add this parameter to their build
method:
GraphQLContext build(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse);
Ability to handle Apollo subscription onConnect
The connect of Apollo subscription allows an optional, custom payload to be sent along. This could be used for authentication for example. To allow this the SubscriptionConnectionListener
has been introduced. The ApolloSubscriptionConnectionListener
provides the onConnect
method which is called during the connect process. It can either return an optional custom object to be stored in the Session
, or you can have the server return an error by throwing an exception.
Apollo subscription keep alive
The implementation of keep alive for Apollo subscriptions was incorrect. It would only send one keep alive message, while it should be sending repeatedly, because otherwise Apollo client will assume the connection is inactive and reconnect. The default implementation therefore now sends keep alive messages every 15 seconds.
The behavior of this keep alive can be configured by passing a SubscriptionConnectionListener
when constructing the GraphQLWebsocketServlet
.
GraphQLWebsocketServlet servlet = new GraphQLWebsocketServlet(queryInvoker, invocationInputFactory, graphQLObjectMapper, subscriptionConnectionListener);
Two static factory methods are available for creating SubscriptionConnectionListener
s for the most common use cases.
Disabling keep alive entirely
ApolloSubscriptionConnectionListener.createWithKeepAliveDisabled();
Setting a custom interval
Keep in mind when setting the custom interval to use a value below 30 seconds, because otherwise it would defeat the purpose and Apollo will disconnect.
ApolloSubscriptionConnectionListener.createWithKeepAliveInterval(Duration.ofSeconds(20));