|
1 | 1 | package graphql.servlet; |
2 | 2 |
|
3 | | -import graphql.schema.GraphQLSchema; |
4 | 3 | import graphql.kickstart.execution.GraphQLObjectMapper; |
5 | 4 | import graphql.kickstart.execution.GraphQLQueryInvoker; |
6 | | -import graphql.kickstart.execution.config.GraphQLSchemaProvider; |
| 5 | +import graphql.schema.GraphQLSchema; |
7 | 6 | import graphql.servlet.config.GraphQLSchemaServletProvider; |
8 | 7 | import graphql.servlet.core.GraphQLServletListener; |
9 | 8 | import graphql.servlet.input.GraphQLInvocationInputFactory; |
10 | | - |
11 | 9 | import java.util.ArrayList; |
12 | 10 | import java.util.List; |
13 | 11 | import java.util.Objects; |
|
17 | 15 | */ |
18 | 16 | public class SimpleGraphQLHttpServlet extends AbstractGraphQLHttpServlet { |
19 | 17 |
|
20 | | - private GraphQLConfiguration configuration; |
21 | | - |
22 | | - public SimpleGraphQLHttpServlet() { |
23 | | - } |
24 | | - |
25 | | - /** |
26 | | - * @deprecated use {@link GraphQLHttpServlet} instead |
27 | | - */ |
28 | | - @Deprecated |
29 | | - public SimpleGraphQLHttpServlet(GraphQLInvocationInputFactory invocationInputFactory, GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQLObjectMapper, List<GraphQLServletListener> listeners, boolean asyncServletMode) { |
30 | | - super(listeners); |
31 | | - this.configuration = GraphQLConfiguration.with(invocationInputFactory) |
32 | | - .with(queryInvoker) |
33 | | - .with(graphQLObjectMapper) |
34 | | - .with(listeners != null ? listeners : new ArrayList<>()) |
35 | | - .with(asyncServletMode) |
36 | | - .build(); |
37 | | - } |
38 | | - |
39 | | - /** |
40 | | - * @deprecated use {@link GraphQLHttpServlet} instead |
41 | | - */ |
42 | | - @Deprecated |
43 | | - public SimpleGraphQLHttpServlet(GraphQLInvocationInputFactory invocationInputFactory, GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQLObjectMapper, List<GraphQLServletListener> listeners, boolean asyncServletMode, long subscriptionTimeout) { |
44 | | - super(listeners); |
45 | | - this.configuration = GraphQLConfiguration.with(invocationInputFactory) |
46 | | - .with(queryInvoker) |
47 | | - .with(graphQLObjectMapper) |
48 | | - .with(listeners != null ? listeners : new ArrayList<>()) |
49 | | - .with(asyncServletMode) |
50 | | - .with(subscriptionTimeout) |
51 | | - .build(); |
| 18 | + private GraphQLConfiguration configuration; |
| 19 | + |
| 20 | + public SimpleGraphQLHttpServlet() { |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * @deprecated use {@link GraphQLHttpServlet} instead |
| 25 | + */ |
| 26 | + @Deprecated |
| 27 | + public SimpleGraphQLHttpServlet(GraphQLInvocationInputFactory invocationInputFactory, |
| 28 | + GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQLObjectMapper, List<GraphQLServletListener> listeners, |
| 29 | + boolean asyncServletMode) { |
| 30 | + super(listeners); |
| 31 | + this.configuration = GraphQLConfiguration.with(invocationInputFactory) |
| 32 | + .with(queryInvoker) |
| 33 | + .with(graphQLObjectMapper) |
| 34 | + .with(listeners != null ? listeners : new ArrayList<>()) |
| 35 | + .with(asyncServletMode) |
| 36 | + .build(); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @deprecated use {@link GraphQLHttpServlet} instead |
| 41 | + */ |
| 42 | + @Deprecated |
| 43 | + public SimpleGraphQLHttpServlet(GraphQLInvocationInputFactory invocationInputFactory, |
| 44 | + GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQLObjectMapper, List<GraphQLServletListener> listeners, |
| 45 | + boolean asyncServletMode, long subscriptionTimeout) { |
| 46 | + super(listeners); |
| 47 | + this.configuration = GraphQLConfiguration.with(invocationInputFactory) |
| 48 | + .with(queryInvoker) |
| 49 | + .with(graphQLObjectMapper) |
| 50 | + .with(listeners != null ? listeners : new ArrayList<>()) |
| 51 | + .with(asyncServletMode) |
| 52 | + .with(subscriptionTimeout) |
| 53 | + .build(); |
| 54 | + } |
| 55 | + |
| 56 | + private SimpleGraphQLHttpServlet(GraphQLConfiguration configuration) { |
| 57 | + this.configuration = Objects.requireNonNull(configuration, "configuration is required"); |
| 58 | + } |
| 59 | + |
| 60 | + public static Builder newBuilder(GraphQLSchema schema) { |
| 61 | + return new Builder(GraphQLInvocationInputFactory.newBuilder(schema).build()); |
| 62 | + } |
| 63 | + |
| 64 | + public static Builder newBuilder(GraphQLSchemaServletProvider schemaProvider) { |
| 65 | + return new Builder(GraphQLInvocationInputFactory.newBuilder(schemaProvider).build()); |
| 66 | + } |
| 67 | + |
| 68 | + public static Builder newBuilder(GraphQLInvocationInputFactory invocationInputFactory) { |
| 69 | + return new Builder(invocationInputFactory); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + protected GraphQLConfiguration getConfiguration() { |
| 74 | + return configuration; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + protected GraphQLQueryInvoker getQueryInvoker() { |
| 79 | + return configuration.getQueryInvoker(); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + protected GraphQLInvocationInputFactory getInvocationInputFactory() { |
| 84 | + return configuration.getInvocationInputFactory(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + protected GraphQLObjectMapper getGraphQLObjectMapper() { |
| 89 | + return configuration.getObjectMapper(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + protected boolean isAsyncServletMode() { |
| 94 | + return configuration.isAsyncServletModeEnabled(); |
| 95 | + } |
| 96 | + |
| 97 | + public static class Builder { |
| 98 | + |
| 99 | + private final GraphQLInvocationInputFactory invocationInputFactory; |
| 100 | + private GraphQLQueryInvoker queryInvoker = GraphQLQueryInvoker.newBuilder().build(); |
| 101 | + private GraphQLObjectMapper graphQLObjectMapper = GraphQLObjectMapper.newBuilder().build(); |
| 102 | + private List<GraphQLServletListener> listeners; |
| 103 | + private boolean asyncServletMode; |
| 104 | + private long subscriptionTimeout; |
| 105 | + |
| 106 | + Builder(GraphQLInvocationInputFactory invocationInputFactory) { |
| 107 | + this.invocationInputFactory = invocationInputFactory; |
52 | 108 | } |
53 | 109 |
|
54 | | - private SimpleGraphQLHttpServlet(GraphQLConfiguration configuration) { |
55 | | - this.configuration = Objects.requireNonNull(configuration, "configuration is required"); |
| 110 | + public Builder withQueryInvoker(GraphQLQueryInvoker queryInvoker) { |
| 111 | + this.queryInvoker = queryInvoker; |
| 112 | + return this; |
56 | 113 | } |
57 | 114 |
|
58 | | - @Override |
59 | | - protected GraphQLConfiguration getConfiguration() { |
60 | | - return configuration; |
| 115 | + public Builder withObjectMapper(GraphQLObjectMapper objectMapper) { |
| 116 | + this.graphQLObjectMapper = objectMapper; |
| 117 | + return this; |
61 | 118 | } |
62 | 119 |
|
63 | | - @Override |
64 | | - protected GraphQLQueryInvoker getQueryInvoker() { |
65 | | - return configuration.getQueryInvoker(); |
| 120 | + public Builder withAsyncServletMode(boolean asyncServletMode) { |
| 121 | + this.asyncServletMode = asyncServletMode; |
| 122 | + return this; |
66 | 123 | } |
67 | 124 |
|
68 | | - @Override |
69 | | - protected GraphQLInvocationInputFactory getInvocationInputFactory() { |
70 | | - return configuration.getInvocationInputFactory(); |
| 125 | + public Builder withListeners(List<GraphQLServletListener> listeners) { |
| 126 | + this.listeners = listeners; |
| 127 | + return this; |
71 | 128 | } |
72 | 129 |
|
73 | | - @Override |
74 | | - protected GraphQLObjectMapper getGraphQLObjectMapper() { |
75 | | - return configuration.getObjectMapper(); |
| 130 | + public Builder withSubscriptionTimeout(long subscriptionTimeout) { |
| 131 | + this.subscriptionTimeout = subscriptionTimeout; |
| 132 | + return this; |
76 | 133 | } |
77 | 134 |
|
78 | | - @Override |
79 | | - protected boolean isAsyncServletMode() { |
80 | | - return configuration.isAsyncServletModeEnabled(); |
81 | | - } |
82 | | - |
83 | | - public static Builder newBuilder(GraphQLSchema schema) { |
84 | | - return new Builder(GraphQLInvocationInputFactory.newBuilder(schema).build()); |
85 | | - } |
86 | | - |
87 | | - public static Builder newBuilder(GraphQLSchemaServletProvider schemaProvider) { |
88 | | - return new Builder(GraphQLInvocationInputFactory.newBuilder(schemaProvider).build()); |
89 | | - } |
90 | | - |
91 | | - public static Builder newBuilder(GraphQLInvocationInputFactory invocationInputFactory) { |
92 | | - return new Builder(invocationInputFactory); |
93 | | - } |
94 | | - |
95 | | - public static class Builder { |
96 | | - private final GraphQLInvocationInputFactory invocationInputFactory; |
97 | | - private GraphQLQueryInvoker queryInvoker = GraphQLQueryInvoker.newBuilder().build(); |
98 | | - private GraphQLObjectMapper graphQLObjectMapper = GraphQLObjectMapper.newBuilder().build(); |
99 | | - private List<GraphQLServletListener> listeners; |
100 | | - private boolean asyncServletMode; |
101 | | - private long subscriptionTimeout; |
102 | | - |
103 | | - Builder(GraphQLInvocationInputFactory invocationInputFactory) { |
104 | | - this.invocationInputFactory = invocationInputFactory; |
105 | | - } |
106 | | - |
107 | | - public Builder withQueryInvoker(GraphQLQueryInvoker queryInvoker) { |
108 | | - this.queryInvoker = queryInvoker; |
109 | | - return this; |
110 | | - } |
111 | | - |
112 | | - public Builder withObjectMapper(GraphQLObjectMapper objectMapper) { |
113 | | - this.graphQLObjectMapper = objectMapper; |
114 | | - return this; |
115 | | - } |
116 | | - |
117 | | - public Builder withAsyncServletMode(boolean asyncServletMode) { |
118 | | - this.asyncServletMode = asyncServletMode; |
119 | | - return this; |
120 | | - } |
121 | | - |
122 | | - public Builder withListeners(List<GraphQLServletListener> listeners) { |
123 | | - this.listeners = listeners; |
124 | | - return this; |
125 | | - } |
126 | | - |
127 | | - public Builder withSubscriptionTimeout(long subscriptionTimeout) { |
128 | | - this.subscriptionTimeout = subscriptionTimeout; |
129 | | - return this; |
130 | | - } |
131 | | - |
132 | | - @Deprecated |
133 | | - public SimpleGraphQLHttpServlet build() { |
134 | | - GraphQLConfiguration configuration = GraphQLConfiguration.with(invocationInputFactory) |
135 | | - .with(queryInvoker) |
136 | | - .with(graphQLObjectMapper) |
137 | | - .with(listeners != null ? listeners : new ArrayList<>()) |
138 | | - .with(asyncServletMode) |
139 | | - .with(subscriptionTimeout) |
140 | | - .build(); |
141 | | - return new SimpleGraphQLHttpServlet(configuration); |
142 | | - } |
| 135 | + @Deprecated |
| 136 | + public SimpleGraphQLHttpServlet build() { |
| 137 | + GraphQLConfiguration configuration = GraphQLConfiguration.with(invocationInputFactory) |
| 138 | + .with(queryInvoker) |
| 139 | + .with(graphQLObjectMapper) |
| 140 | + .with(listeners != null ? listeners : new ArrayList<>()) |
| 141 | + .with(asyncServletMode) |
| 142 | + .with(subscriptionTimeout) |
| 143 | + .build(); |
| 144 | + return new SimpleGraphQLHttpServlet(configuration); |
143 | 145 | } |
| 146 | + } |
144 | 147 | } |
0 commit comments