Skip to content

Commit f1a512c

Browse files
authored
Merge pull request #3945 from graphql-java/static-configuration-support
A generalised configuration mechanism
2 parents 00057ef + 3c5c911 commit f1a512c

File tree

7 files changed

+692
-3
lines changed

7 files changed

+692
-3
lines changed

src/main/java/graphql/ExecutionInput.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ public static class Builder {
222222
private ExecutionId executionId;
223223
private AtomicBoolean cancelled = new AtomicBoolean(false);
224224

225+
/**
226+
* Package level access to the graphql context
227+
* @return shhh but it's the graphql context
228+
*/
229+
GraphQLContext graphQLContext() {
230+
return graphQLContext;
231+
}
232+
225233
public Builder query(String query) {
226234
this.query = assertNotNull(query, () -> "query can't be null");
227235
return this;

src/main/java/graphql/GraphQL.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,72 @@
8585
@PublicApi
8686
public class GraphQL {
8787

88+
/**
89+
* This allows you to control "unusual" aspects of the GraphQL system
90+
* including some JVM wide settings
91+
* <p>
92+
* This is named unusual because in general we don't expect you to
93+
* have to make ths configuration by default, but you can opt into certain features
94+
* or disable them if you want to.
95+
*
96+
* @return a {@link GraphQLUnusualConfiguration} object
97+
*/
98+
public static GraphQLUnusualConfiguration unusualConfiguration() {
99+
return new GraphQLUnusualConfiguration();
100+
}
101+
102+
/**
103+
* This allows you to control "unusual" per execution aspects of the GraphQL system
104+
* <p>
105+
* This is named unusual because in general we don't expect you to
106+
* have to make ths configuration by default, but you can opt into certain features
107+
* or disable them if you want to.
108+
*
109+
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
110+
*/
111+
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(ExecutionInput executionInput) {
112+
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(executionInput.getGraphQLContext());
113+
}
114+
115+
/**
116+
* This allows you to control "unusual" per execution aspects of the GraphQL system
117+
* <p>
118+
* This is named unusual because in general we don't expect you to
119+
* have to make ths configuration by default, but you can opt into certain features
120+
* or disable them if you want to.
121+
*
122+
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
123+
*/
124+
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(ExecutionInput.Builder executionInputBuilder) {
125+
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(executionInputBuilder.graphQLContext());
126+
}
127+
128+
/**
129+
* This allows you to control "unusual" per execution aspects of the GraphQL system
130+
* <p>
131+
* This is named unusual because in general we don't expect you to
132+
* have to make ths configuration by default, but you can opt into certain features
133+
* or disable them if you want to.
134+
*
135+
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
136+
*/
137+
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(GraphQLContext graphQLContext) {
138+
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(graphQLContext);
139+
}
140+
141+
/**
142+
* This allows you to control "unusual" per execution aspects of the GraphQL system
143+
* <p>
144+
* This is named unusual because in general we don't expect you to
145+
* have to make ths configuration by default, but you can opt into certain features
146+
* or disable them if you want to.
147+
*
148+
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
149+
*/
150+
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(GraphQLContext.Builder graphQLContextBuilder) {
151+
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(graphQLContextBuilder);
152+
}
153+
88154
private final GraphQLSchema graphQLSchema;
89155
private final ExecutionStrategy queryStrategy;
90156
private final ExecutionStrategy mutationStrategy;

src/main/java/graphql/GraphQLContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ public Builder put(
326326
);
327327
}
328328

329+
public Object get(Object key) {
330+
return map.get(key);
331+
}
332+
333+
public boolean getBoolean(Object key) {
334+
return Boolean.parseBoolean(String.valueOf(get(key)));
335+
}
336+
337+
329338
public Builder of(
330339
Object key1, Object value1
331340
) {

0 commit comments

Comments
 (0)