Repository: graphql-java/graphql-java

Issue #2238: schema fails to build for directive argument with recursive argument as input 
Created: 2021-03-08T11:41:42Z
Describe the bug
Using a recursive input type as argument for an directive will result in the following error when compiling the schema:
Internal error: should never happen: cannot build value of type Recursive from object class ObjectValue with instance ObjectValue{objectFields=[ObjectField{name='name', value=StringValue{value='test'}}]}
graphql.AssertException: Internal error: should never happen: cannot build value of type Recursive from object class ObjectValue with instance ObjectValue{objectFields=[ObjectField{name='name', value=StringValue{value='test'}}]}
	at graphql.Assert.assertShouldNeverHappen(Assert.java:53)
	at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:282)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildObjectValue$1(SchemaGeneratorHelper.java:303)
	at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at graphql.schema.idl.SchemaGeneratorHelper.buildObjectValue(SchemaGeneratorHelper.java:300)
	at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:280)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirectiveArgument(SchemaGeneratorHelper.java:403)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildDirective$9(SchemaGeneratorHelper.java:384)
	at graphql.collect.ImmutableKit.map(ImmutableKit.java:83)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirective(SchemaGeneratorHelper.java:384)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirective(SchemaGeneratorHelper.java:355)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirectives(SchemaGeneratorHelper.java:731)
	at graphql.schema.idl.SchemaGeneratorHelper.buildObjectType(SchemaGeneratorHelper.java:825)
	at graphql.schema.idl.SchemaGeneratorHelper.buildOutputType(SchemaGeneratorHelper.java:953)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildAdditionalTypes$46(SchemaGeneratorHelper.java:1181)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
	at graphql.schema.idl.SchemaGeneratorHelper.buildAdditionalTypes(SchemaGeneratorHelper.java:1171)
	at graphql.schema.idl.SchemaGenerator.makeExecutableSchemaImpl(SchemaGenerator.java:111)
	at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:96)

To Reproduce
Compile following schema:
directive @test(arg: Recursive) on OBJECT
input Recursive {
  deeper: Recursive
  name: String
}
type Test @test(arg: { deeper: {name: "test"}}){
  field: String
}
type Query {
}

Duplicate issue #2290: Recursive directive inputs don't work
Created: 2021-04-14T00:52:51Z
Describe the bug
Directives with recursive inputs fail get instantiated. (Affects v16.2)
Example:
input MyInput {
  a: String
  b: MyInput
}
directive @myDirective(x: MyInput) on FIELD_DEFINITION
type Query {
  f: String @myDirective(x: {b: {a:"yada"}})
}
To Reproduce
public class Test {
    public static void main(String[] args) {
        String sdl =
          "input MyInput {\n" +
          "  a: String\n" +
          "  b: MyInput\n" +
          "}\n" +
          "directive @myDirective(x: MyInput) on FIELD_DEFINITION\n" +
          "type Query {\n" +
          "  f: String @myDirective(x: {b: {a:\"yada\"}})\n" +
          "}\n";
        TypeDefinitionRegistry registry = new SchemaParser().parse(sdl);
        UnExecutableSchemaGenerator.makeUnExecutableSchema(registry);
    }
Stacktrace
Exception in thread "main" graphql.AssertException: Internal error: should never happen: cannot build value of type MyInput from object class ObjectValue with instance ObjectValue{objectFields=[ObjectField{name='a', value=StringValue{value='yada'}}]}
	at graphql.Assert.assertShouldNeverHappen(Assert.java:53)
	at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:282)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildObjectValue$1(SchemaGeneratorHelper.java:303)
	at graphql.com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at graphql.schema.idl.SchemaGeneratorHelper.buildObjectValue(SchemaGeneratorHelper.java:300)
	at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:280)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirectiveArgument(SchemaGeneratorHelper.java:403)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildDirective$9(SchemaGeneratorHelper.java:384)
	at graphql.collect.ImmutableKit.map(ImmutableKit.java:83)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirective(SchemaGeneratorHelper.java:384)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirective(SchemaGeneratorHelper.java:355)
	at graphql.schema.idl.SchemaGeneratorHelper.buildDirectives(SchemaGeneratorHelper.java:731)
	at graphql.schema.idl.SchemaGeneratorHelper.buildField(SchemaGeneratorHelper.java:980)
	at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildObjectType$32(SchemaGeneratorHelper.java:834)
	at graphql.com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
	at graphql.schema.idl.SchemaGeneratorHelper.buildObjectType(SchemaGeneratorHelper.java:833)
	at graphql.schema.idl.SchemaGeneratorHelper.buildOutputType(SchemaGeneratorHelper.java:953)
	at graphql.schema.idl.SchemaGeneratorHelper.buildOperations(SchemaGeneratorHelper.java:1088)
	at graphql.schema.idl.SchemaGenerator.makeExecutableSchemaImpl(SchemaGenerator.java:92)
	at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:79)
	at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:52)
	at graphql.schema.idl.UnExecutableSchemaGenerator.makeUnExecutableSchema(UnExecutableSchemaGenerator.java:28)
	at com.credify.graphql.schema.transform.TransformerTestUtils.main(TransformerTestUtils.java:39)

Potential solution
The issue is that the requiredType is a GraphQLTypeReference, it could be resolved by name from the BuildContext.inputGTypes map.

Closing comment (2021-04-15T15:28:56Z): duplicate of #2238