Skip to content

A generalised configuration mechanism #3945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/graphql/ExecutionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ public static class Builder {
private ExecutionId executionId;
private AtomicBoolean cancelled = new AtomicBoolean(false);

/**
* Package level access to the graphql context
* @return shhh but it's the graphql context
*/
GraphQLContext graphQLContext() {
return graphQLContext;
}

public Builder query(String query) {
this.query = assertNotNull(query, () -> "query can't be null");
return this;
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/graphql/GraphQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,72 @@
@PublicApi
public class GraphQL {

/**
* This allows you to control "unusual" aspects of the GraphQL system
* including some JVM wide settings
* <p>
* This is named unusual because in general we don't expect you to
* have to make ths configuration by default, but you can opt into certain features
* or disable them if you want to.
*
* @return a {@link GraphQLUnusualConfiguration} object
*/
public static GraphQLUnusualConfiguration unusualConfiguration() {
return new GraphQLUnusualConfiguration();
}

/**
* This allows you to control "unusual" per execution aspects of the GraphQL system
* <p>
* This is named unusual because in general we don't expect you to
* have to make ths configuration by default, but you can opt into certain features
* or disable them if you want to.
*
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
*/
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(ExecutionInput executionInput) {
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(executionInput.getGraphQLContext());
}

/**
* This allows you to control "unusual" per execution aspects of the GraphQL system
* <p>
* This is named unusual because in general we don't expect you to
* have to make ths configuration by default, but you can opt into certain features
* or disable them if you want to.
*
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
*/
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(ExecutionInput.Builder executionInputBuilder) {
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(executionInputBuilder.graphQLContext());
}

/**
* This allows you to control "unusual" per execution aspects of the GraphQL system
* <p>
* This is named unusual because in general we don't expect you to
* have to make ths configuration by default, but you can opt into certain features
* or disable them if you want to.
*
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
*/
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(GraphQLContext graphQLContext) {
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(graphQLContext);
}

/**
* This allows you to control "unusual" per execution aspects of the GraphQL system
* <p>
* This is named unusual because in general we don't expect you to
* have to make ths configuration by default, but you can opt into certain features
* or disable them if you want to.
*
* @return a {@link GraphQLUnusualConfiguration.GraphQLContextConfiguration} object
*/
public static GraphQLUnusualConfiguration.GraphQLContextConfiguration unusualConfiguration(GraphQLContext.Builder graphQLContextBuilder) {
return new GraphQLUnusualConfiguration.GraphQLContextConfiguration(graphQLContextBuilder);
}

private final GraphQLSchema graphQLSchema;
private final ExecutionStrategy queryStrategy;
private final ExecutionStrategy mutationStrategy;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/graphql/GraphQLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ public Builder put(
);
}

public Object get(Object key) {
return map.get(key);
}

public boolean getBoolean(Object key) {
return Boolean.parseBoolean(String.valueOf(get(key)));
}


public Builder of(
Object key1, Object value1
) {
Expand Down
Loading
Loading