You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating the Servlet class requires various parameters to be provided at the moment. We're working on simplifying
52
+
this, to make it easier to get started. For now, take a look at [Create a Servlet class](https://www.graphql-java-kickstart.com/servlet/getting-started/#create-a-servlet-class)
53
+
to see what's needed to create a Servlet with a schema.
54
+
55
+
## Using the latest development build
56
+
57
+
Snapshot versions of the current `master` branch are available on JFrog. Check the next snapshot version in
The servlet supports the following request formats:
34
-
* GET request with query parameters:
90
+
* GET request to `../schema.json`: Get the result of an introspection query.
91
+
* GET request with query parameters (query only, no mutation):
35
92
* query
36
93
* operationName (optional)
37
94
* variables (optional)
@@ -45,51 +102,52 @@ The servlet supports the following request formats:
45
102
* variables (optional)
46
103
* POST multipart parts named "query", "operationName" (optional), and "variables" (optional)
47
104
48
-
## Standalone servlet
105
+
## Servlet Listeners
49
106
50
-
The simplest form of the servlet takes a graphql-java `GraphQLSchema` and an `ExecutionStrategy`:
107
+
You can also add [servlet listeners](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLServletListener.java) to an existing servlet.
108
+
These listeners provide hooks into query execution (before, success, failure, and finally) and servlet execution (before, success, error, and finally):
You can also add [operation listeners](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLOperationListener.java) and [servlet listeners](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLServletListener.java) to an existing servlet.
60
-
These listeners provide hooks into query execution (before, on success, and on failure) and servlet execution (before, on error, and finally):
Relay.js support is provided by the [EnhancedExecutionStrategy](https://github.com/graphql-java/graphql-java-annotations/blob/master/src/main/java/graphql/annotations/EnhancedExecutionStrategy.java) of [graphql-java-annotations](https://github.com/graphql-java/graphql-java-annotations).
100
158
You **MUST** pass this execution strategy to the servlet for Relay.js support.
101
159
102
-
This is the default execution strategy for the `OsgiGraphQLServlet`, and must be added as a dependency when using that servlet.
160
+
This is the default execution strategy for the `OsgiGraphQLHttpServlet`, and must be added as a dependency when using that servlet.
161
+
162
+
## Apollo support
163
+
164
+
Query batching is supported, no configuration required.
The [OsgiGraphQLServlet](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/OsgiGraphQLServlet.java) uses a "provider" model to supply the servlet with the required objects:
117
-
*[GraphQLQueryProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLQueryProvider.java): Provides query fields to the GraphQL schema.
118
-
*[GraphQLMutationProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLMutationProvider.java): Provides mutation fields to the GraphQL schema.
119
-
*[GraphQLTypesProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLTypesProvider.java): Provides type information to the GraphQL schema.
120
-
*[ExecutionStrategyProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/ExecutionStrategyProvider.java): Provides an execution strategy for running each query.
121
-
*[GraphQLContextBuilder](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLContextBuilder.java): Builds a context for running each query.
178
+
The [OsgiGraphQLHttpServlet](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/OsgiGraphQLHttpServlet.java) uses a "provider" model to supply the servlet with the required objects:
179
+
*[GraphQLQueryProvider](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLQueryProvider.java): Provides query fields to the GraphQL schema.
180
+
*[GraphQLMutationProvider](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLMutationProvider.java): Provides mutation fields to the GraphQL schema.
181
+
*[GraphQLTypesProvider](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLTypesProvider.java): Provides type information to the GraphQL schema.
182
+
*[ExecutionStrategyProvider](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/ExecutionStrategyProvider.java): Provides an execution strategy for running each query.
183
+
*[GraphQLContextBuilder](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLContextBuilder.java): Builds a context for running each query.
122
184
123
185
## Examples
124
186
@@ -169,3 +231,61 @@ And here is a sample src/main/feature/feature.xml file to add some dependencies
169
231
Here's an example of a GraphQL provider that implements three interfaces at the same time.
It is possible to use dataloaders in a request scope by customizing [GraphQLContextBuilder](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLContextBuilder.java).
238
+
And instantiating a new [DataLoaderRegistry](https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoaderRegistry.java) for each GraphQLContext.
It is then possible to access the [DataLoader](https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoader.java) in the resolvers by accessing the [DataLoaderRegistry] from context. For eg:
282
+
```java
283
+
publicCompletableFuture<String> getEmailAddress(User user, DataFetchingEnvironment dfe) { // User is the graphQL type
0 commit comments