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
12 changes: 8 additions & 4 deletions src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,24 @@ GraphQLDirective buildAppliedDirective(BuildContext buildCtx,
});
builder.repeatable(graphQLDirective.isRepeatable());

List<GraphQLArgument> appliedArguments = map(directive.getArguments(), arg -> buildAppliedDArgument(arg, graphQLDirective));
builder.definition(buildCtx.isCaptureAstDefinitions() ? graphQLDirective.getDefinition() : null);

List<GraphQLArgument> appliedArguments = map(directive.getArguments(), arg -> buildAppliedDArgument(buildCtx, arg, graphQLDirective));

appliedArguments = transferMissingArguments(buildCtx, appliedArguments, graphQLDirective);
appliedArguments.forEach(builder::argument);

return builder.build();
}

private GraphQLArgument buildAppliedDArgument(Argument arg, GraphQLDirective directiveDefinition) {
private GraphQLArgument buildAppliedDArgument(BuildContext buildCtx, Argument arg, GraphQLDirective directiveDefinition) {
GraphQLArgument directiveDefArgument = directiveDefinition.getArgument(arg.getName());
GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
builder.name(arg.getName());
GraphQLInputType inputType = directiveDefArgument.getType();
builder.type(inputType);
builder.name(arg.getName())
.type(inputType)
.definition(buildCtx.isCaptureAstDefinitions() ? directiveDefArgument.getDefinition() : null);

// we know it is a literal because it was created by SchemaGenerator
if (directiveDefArgument.getArgumentDefaultValue().isSet()) {
builder.defaultValueLiteral((Value) directiveDefArgument.getArgumentDefaultValue().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class SchemaGeneratorTest extends Specification {
}

static GraphQLSchema schema(String sdl, RuntimeWiring runtimeWiring) {
return TestUtil.schema(sdl, runtimeWiring)
SchemaGenerator.Options options = defaultOptions().captureAstDefinitions(true)
return TestUtil.schema(options, sdl, runtimeWiring)
}


Expand Down Expand Up @@ -1311,8 +1312,11 @@ class SchemaGeneratorTest extends Specification {
expect:
type.getDirectives().size() == 4
type.getDirectives()[0].name == "directive1"
type.getDirectives()[0].getDefinition() != null
type.getDirectives()[1].name == "directive2"
type.getDirectives()[1].getDefinition() != null
type.getDirectives()[2].name == "directive3"
type.getDirectives()[2].getDefinition() != null

// test that fields can have directives as well

Expand Down