Skip to content

Commit 4f18d90

Browse files
committed
Move from readme to documentation
1 parent cba36c6 commit 4f18d90

File tree

1 file changed

+1
-173
lines changed

1 file changed

+1
-173
lines changed

README.md

Lines changed: 1 addition & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This project wraps the Java implementation of GraphQL provided by [GraphQL Java]
99
See [GraphQL Java documentation](https://www.graphql-java.com/documentation/latest/) for more in depth details
1010
regarding GraphQL Java itself.
1111

12-
We try to stay up to date with GraphQL Java as much as possible. The current version supports **GraphQL Java 11.0**.
12+
We try to stay up to date with GraphQL Java as much as possible. The current version supports **GraphQL Java 14.0**.
1313

1414
This project requires at least Java 8.
1515

@@ -103,67 +103,13 @@ The servlet supports the following request formats:
103103
* POST multipart parts named "query", "operationName" (optional), and "variables" (optional)
104104
* POST with Content Type "application/graphql" will treat the HTTP POST body contents as the GraphQL query string
105105

106-
## Servlet Listeners
107-
108-
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.
109-
These listeners provide hooks into query execution (before, success, failure, and finally) and servlet execution (before, success, error, and finally):
110-
```java
111-
servlet.addListener(new GraphQLServletListener() {
112-
@Override
113-
GraphQLServletListener.RequestCallback onRequest(HttpServletRequest request, HttpServletResponse response) {
114-
115-
return new GraphQLServletListener.RequestCallback() {
116-
@Override
117-
void onSuccess(HttpServletRequest request, HttpServletResponse response) {
118-
119-
}
120-
121-
@Override
122-
void onError(HttpServletRequest request, HttpServletResponse response, Throwable throwable) {
123-
124-
}
125-
126-
@Override
127-
void onFinally(HttpServletRequest request, HttpServletResponse response) {
128-
129-
}
130-
}
131-
}
132-
133-
@Override
134-
GraphQLServletListener.OperationCallback onOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables) {
135-
136-
return new GraphQLServletListener.OperationCallback() {
137-
@Override
138-
void onSuccess(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data) {
139-
140-
}
141-
142-
@Override
143-
void onError(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data, List<GraphQLError> errors) {
144-
145-
}
146-
147-
@Override
148-
void onFinally(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data) {
149-
150-
}
151-
}
152-
}
153-
})
154-
```
155-
156106
## Relay.js support
157107

158108
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).
159109
You **MUST** pass this execution strategy to the servlet for Relay.js support.
160110

161111
This is the default execution strategy for the `OsgiGraphQLHttpServlet`, and must be added as a dependency when using that servlet.
162112

163-
## Apollo support
164-
165-
Query batching is supported, no configuration required.
166-
167113
## Spring Framework support
168114

169115
To use the servlet with Spring Framework, either use the [Spring Boot starter](https://github.com/graphql-java/graphql-spring-boot) or simply define a `ServletRegistrationBean` in a web app:
@@ -173,121 +119,3 @@ ServletRegistrationBean graphQLServletRegistrationBean(GraphQLSchema schema, Exe
173119
return new ServletRegistrationBean(new SimpleGraphQLServlet(schema, executionStrategy, operationListeners), "/graphql");
174120
}
175121
```
176-
177-
## OSGI support
178-
179-
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:
180-
* [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.
181-
* [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.
182-
* [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.
183-
* [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.
184-
* [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.
185-
186-
## Examples
187-
188-
You can now find some example on how to use graphql-java-servlet.
189-
190-
### OSGi Examples
191-
192-
#### Requirements
193-
194-
The OSGi examples use Maven as a build tool because it requires plugins that are not (yet) available for Gradle.
195-
Therefore you will need Maven 3.2+.
196-
197-
#### Building & running the OSGi examples
198-
199-
You can build the OSGi examples sub-projects by simply executing the following command from the examples/osgi directory:
200-
201-
mvn clean install
202-
203-
This will generate a complete Apache Karaf distribution in the following files:
204-
205-
examples/osgi/apache-karaf-package/target/graphql-java-servlet-osgi-examples-apache-karaf-package-VERSION.tar.gz(.zip)
206-
207-
You can simply uncompress this file and launch the OSGi server using the command from the uncompressed directory:
208-
209-
bin/karaf
210-
211-
You should then be able to access the GraphQL endpoint at the following URL once the server is started:
212-
213-
http://localhost:8181/graphql/schema.json
214-
215-
If you see the JSON result of an introspection query, then all is ok. If not, check the data/log/karaf.log file for
216-
any errors.
217-
218-
We also provide a script file to do all of the building and running at once (only for Linux / MacOS ):
219-
220-
./buildAndRun.sh
221-
222-
#### Deploying inside Apache Karaf server
223-
224-
You can use the graphql-java-servlet as part of an Apache Karaf feature, as you can see in the example project here:
225-
* [pom.xml](examples/osgi/apache-karaf-feature/pom.xml)
226-
227-
And here is a sample src/main/feature/feature.xml file to add some dependencies on other features:
228-
* [feature.xml](examples/osgi/apache-karaf-feature/src/main/feature/feature.xml)
229-
230-
#### Example GraphQL provider implementation
231-
232-
Here's an example of a GraphQL provider that implements three interfaces at the same time.
233-
234-
* [ExampleGraphQLProvider](examples/osgi/providers/src/main/java/graphql/servlet/examples/osgi/ExampleGraphQLProvider.java)
235-
236-
## Context and DataLoader settings
237-
238-
It is possible to create context, and consequently dataloaders, in both a request scope and a per query scope by customizing [GraphQLContextBuilder](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/context/GraphQLContextBuilder.java) and selecting the appropriate [ContextSetting](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/context/ContextSetting.java) with the provided [GraphQLConfiguration](https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/config/GraphQLConfiguration.java).
239-
A new [DataLoaderRegistry](https://github.com/graphql-java/java-dataloader/blob/master/src/main/java/org/dataloader/DataLoaderRegistry.java) should be created in each call to the GraphQLContextBuilder, and the servlet will call the builder at the appropriate times.
240-
For eg:
241-
```java
242-
public class CustomGraphQLContextBuilder implements GraphQLContextBuilder {
243-
244-
private final DataLoader userDataLoader;
245-
246-
public CustomGraphQLContextBuilder(DataLoader userDataLoader) {
247-
this.userDataLoader = userDataLoader;
248-
}
249-
250-
251-
public GraphQLContext build() {
252-
return new DefaultGraphQLContext();
253-
}
254-
255-
public GraphQLContext build(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
256-
return DefaultGraphQLServletContext.createServletContext()
257-
.with(httpServletRequest)
258-
.with(httpServletResponse)
259-
.with(buildDataLoaderRegistry())
260-
.build();
261-
}
262-
263-
public GraphQLContext build(Session session, HandshakeRequest handshakeRequest) {
264-
return DefaultGraphQLWebSocketContext.createWebSocketContext()
265-
.with(session)
266-
.with(handshakeRequest)
267-
.with(buildDataLoaderRegistry())
268-
.build();
269-
}
270-
271-
private DataLoaderRegistry buildDataLoaderRegistry() {
272-
DataLoaderRegistry registry = new DataLoaderRegistry();
273-
for (BatchLoader batchLoader: this.batchLoaders) {
274-
registry.register(batchLoader.getClass().getSimpleName(), DataLoader.newDataLoader(batchLoader));
275-
}
276-
return registry;
277-
}
278-
}
279-
```
280-
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:
281-
```java
282-
public CompletableFuture<String> getEmailAddress(User user, DataFetchingEnvironment dfe) { // User is the graphQL type
283-
final DataLoader<String, UserDetail> userDataloader =
284-
dfe.getContext().getDataLoaderRegistry().get().getDataLoader("userDataLoader"); // UserDetail is the data that is loaded
285-
286-
return userDataloader.load(User.getName())
287-
.thenApply(userDetail -> userDetail != null ? userDetail.getEmailAddress() : null);
288-
}
289-
290-
```
291-
If per request is selected this will cause all queries within the http request, if using a batch, to share dataloader caches and batch together load calls as efficently as possible. The dataloaders are dispatched using instrumentation and the correct instrumentation will be selected according to the ContextSetting. The default context setting in GraphQLConfiguration is per query.
292-
293-
Two additional context settings are provided, one for each of the previous settings but without the addition of the Dataloader dispatching instrumentation. This is useful for those not using Dataloaders or wanting to supply their own dispatching instrumentation though the instrumentation supplier within the GraphQLQueryInvoker.

0 commit comments

Comments
 (0)