Skip to content
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
5 changes: 5 additions & 0 deletions src/main/java/graphql/schema/idl/RuntimeWiring.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.schema.idl;

import graphql.DeprecatedAt;
import graphql.PublicApi;
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLCodeRegistry;
Expand Down Expand Up @@ -352,7 +353,11 @@ public Builder comparatorRegistry(GraphqlTypeComparatorRegistry comparatorRegist
* @param schemaGeneratorPostProcessing the non null schema transformer to add
*
* @return the runtime wiring builder
* @deprecated This mechanism can be achieved in a better way via {@link graphql.schema.SchemaTransformer}
* after the schema is built
*/
@Deprecated
@DeprecatedAt(value = "2022-10-29")
public Builder transformer(SchemaGeneratorPostProcessing schemaGeneratorPostProcessing) {
this.schemaGeneratorPostProcessings.add(assertNotNull(schemaGeneratorPostProcessing));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static graphql.util.TraversalControl.CONTINUE;

@Internal
class SchemaDirectiveWiringSchemaGeneratorPostProcessing implements SchemaGeneratorPostProcessing {
class SchemaDirectiveWiringSchemaGeneratorPostProcessing {

private final SchemaGeneratorDirectiveHelper generatorDirectiveHelper = new SchemaGeneratorDirectiveHelper();
private final TypeDefinitionRegistry typeRegistry;
Expand All @@ -41,7 +41,6 @@ public SchemaDirectiveWiringSchemaGeneratorPostProcessing(TypeDefinitionRegistry
}


@Override
public GraphQLSchema process(GraphQLSchema originalSchema) {
codeRegistryBuilder.trackChanges();
Visitor visitor = new Visitor();
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/graphql/schema/idl/SchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import graphql.schema.GraphQLType;
import graphql.schema.idl.errors.SchemaProblem;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -116,22 +115,23 @@ private GraphQLSchema makeExecutableSchemaImpl(TypeDefinitionRegistry typeRegist
});
GraphQLSchema graphQLSchema = schemaBuilder.build();

List<SchemaGeneratorPostProcessing> schemaTransformers = new ArrayList<>();

// we check if there are any SchemaDirectiveWiring's in play and if there are
// we add this to enable them. By not adding it always, we save unnecessary
// schema build traversals
if (buildCtx.isDirectiveWiringRequired()) {
// handle directive wiring AFTER the schema has been built and hence type references are resolved at callback time
schemaTransformers.add(
new SchemaDirectiveWiringSchemaGeneratorPostProcessing(
buildCtx.getTypeRegistry(),
buildCtx.getWiring(),
buildCtx.getCodeRegistry())
);
SchemaDirectiveWiringSchemaGeneratorPostProcessing directiveWiringProcessing = new SchemaDirectiveWiringSchemaGeneratorPostProcessing(
buildCtx.getTypeRegistry(),
buildCtx.getWiring(),
buildCtx.getCodeRegistry());
graphQLSchema = directiveWiringProcessing.process(graphQLSchema);
}
schemaTransformers.addAll(buildCtx.getWiring().getSchemaGeneratorPostProcessings());

for (SchemaGeneratorPostProcessing postProcessing : schemaTransformers) {
//
// SchemaGeneratorPostProcessing is deprecated but for now we continue to run them
//
for (SchemaGeneratorPostProcessing postProcessing : buildCtx.getWiring().getSchemaGeneratorPostProcessings()) {
graphQLSchema = postProcessing.process(graphQLSchema);
}
return graphQLSchema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package graphql.schema.idl;

import graphql.DeprecatedAt;
import graphql.PublicSpi;
import graphql.schema.GraphQLSchema;

/**
* These are called by the {@link SchemaGenerator} after a valid schema has been built
* and they can then adjust it accordingly with some sort of post processing.
*
* @deprecated This mechanism can be achieved in a better way via {@link graphql.schema.SchemaTransformer}
* after the schema is built
*/
@PublicSpi
@Deprecated
@DeprecatedAt(value = "2022-10-29")
public interface SchemaGeneratorPostProcessing {

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1831,14 +1831,14 @@ class SchemaGeneratorTest extends Specification {

def extraDirective = (GraphQLDirective.newDirective()).name("extra")
.argument(GraphQLArgument.newArgument().name("value").type(GraphQLString)).build()
def transformer = new SchemaGeneratorPostProcessing() {
def transformer = new SchemaGeneratorPostProcessing() { // Retained to show deprecated code is still run
@Override
GraphQLSchema process(GraphQLSchema originalSchema) {
originalSchema.transform({ builder -> builder.additionalDirective(extraDirective) })
}
}
def wiring = RuntimeWiring.newRuntimeWiring()
.transformer(transformer)
.transformer(transformer) // Retained to show deprecated code is still run
.build()
GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(types, wiring)
expect:
Expand Down