Skip to content

Commit 1b374cb

Browse files
authored
Update README.md
1 parent 767f289 commit 1b374cb

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

README.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This module implements a GraphQL Java Servlet. It also supports Relay.js and OSG
77

88
# Downloading
99

10-
You can download it from maven central:
10+
You can download releases from maven central:
1111

1212
```groovy
1313
repositories {
@@ -29,12 +29,62 @@ dependencies {
2929

3030
# Usage
3131

32-
The are a few important components this package provides:
32+
The servlet supports both GET and POST.
33+
In POST, plain request body containing JSON is supported, as well as a multipart upload with a part called 'graphql'.
3334

34-
* GraphQLQueryProvider/GraphQLMutationProvider interfaces. These will allow you
35-
to define which "domain model" views and which mutations you are going to expose.
36-
* GraphQLServlet as an entry point servlet. Use `bindQueryProvider`/`bindMutationProvider` or automatically wire
37-
them in OSGi.
35+
## Standalone servlet
3836

39-
Both GET and POST are supported. In POST, plain request body with a JSON is supported, as well as a multipart with a part
40-
called 'graphql'.
37+
The simplest form of the servlet takes a graphql-java `GraphQLSchema` and an `ExecutionStrategy`:
38+
```java
39+
GraphQLServlet servlet = new SimpleGraphQLServlet(schema, executionStrategy);
40+
41+
// or
42+
43+
GraphQLServlet servlet = new SimpleGraphQLServlet(schema, executionStrategy, operationListeners);
44+
```
45+
46+
You can also add [listeners](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLOperationListener.java) to an existing servlet.
47+
These listeners provide hooks into query execution - before, on success, and on failure:
48+
```java
49+
servlet.addOperationListener(new GraphQLOperationListener() {
50+
@Override
51+
public void beforeGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables) {
52+
53+
}
54+
55+
@Override
56+
public void onSuccessfulGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, Object data) {
57+
58+
}
59+
60+
@Override
61+
public void onFailedGraphQLOperation(GraphQLContext context, String operationName, String query, Map<String, Object> variables, List<GraphQLError> errors) {
62+
63+
}
64+
});
65+
```
66+
67+
## Relay.js support
68+
69+
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).
70+
You **MUST** pass this execution strategy to the servlet for Relay.js support.
71+
This is the default execution strategy for the `OsgiGraphQLServlet`, and must be added as a dependency when using that servlet.
72+
73+
## Spring Framework support
74+
75+
To use the servlet with Spring Framework, simply define a `ServletRegistrationBean` bean in a web app:
76+
```java
77+
@Bean
78+
ServletRegistrationBean graphQLServletRegistrationBean(GraphQLSchema schema, ExecutionStrategy executionStrategy, List<GraphQLOperationListener> operationListeners) {
79+
return new ServletRegistrationBean(new SimpleGraphQLServlet(schema, executionStrategy, operationListeners), "/graphql");
80+
}
81+
```
82+
83+
## OSGI support
84+
85+
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:
86+
* [GraphQLQueryProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLQueryProvider.java): Provides query objects to the GraphQL schema.
87+
* [GraphQLMutationProvider](https://github.com/graphql-java/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/GraphQLMutationProvider.java): Provides mutation objects to the GraphQL schema.
88+
* [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.
89+
* [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.
90+
* [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.

0 commit comments

Comments
 (0)