Exception while parsing schema.json
See original GitHub issuegraphql-java version: 12.0
Describe the bug
SchemaPrinter().print(document)
throws following error.
graphql.AssertException: Internal error: should never happen: cannot build value of RepositoryAffiliation from StringValue{value='OWNER'}
at graphql.Assert.assertShouldNeverHappen(Assert.java:44)
at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:94)
at graphql.schema.idl.SchemaGeneratorHelper.lambda$buildValue$0(SchemaGeneratorHelper.java:90)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at graphql.schema.idl.SchemaGeneratorHelper.buildValue(SchemaGeneratorHelper.java:90)
at graphql.schema.idl.SchemaGenerator.buildArgument(SchemaGenerator.java:812)
at graphql.schema.idl.SchemaGenerator.lambda$buildField$23(SchemaGenerator.java:695)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:694)
at graphql.schema.idl.SchemaGenerator.lambda$buildInterfaceType$13(SchemaGenerator.java:533)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildInterfaceType(SchemaGenerator.java:532)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:413)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.lambda$buildUnionType$16(SchemaGenerator.java:563)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildUnionType(SchemaGenerator.java:562)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:415)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.buildField(SchemaGenerator.java:697)
at graphql.schema.idl.SchemaGenerator.lambda$buildObjectType$6(SchemaGenerator.java:476)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at graphql.schema.idl.SchemaGenerator.buildObjectType(SchemaGenerator.java:475)
at graphql.schema.idl.SchemaGenerator.buildOutputType(SchemaGenerator.java:411)
at graphql.schema.idl.SchemaGenerator.makeExecutableSchemaImpl(SchemaGenerator.java:287)
at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:265)
at graphql.schema.idl.SchemaGenerator.makeExecutableSchema(SchemaGenerator.java:237)
at graphql.schema.idl.UnExecutableSchemaGenerator.makeUnExecutableSchema(UnExecutableSchemaGenerator.java:28)
at graphql.schema.idl.SchemaPrinter.print(SchemaPrinter.java:206)
at com.codingfeline.kgql.gradle.KgqlPluginTest.testSchema(KgqlPluginTest.kt:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
To Reproduce
I’m using GitHub GraphQL API’s schema and trying to create actual schema from schema.json. Here’s the schema.json and a query I used
val schemaFile = File("schema.json")
val json = JsonSlurper().parseText(schemaFile.readText()) as Map<String, Any>
val schema = IntrospectionResultToSchema().createSchemaDefinition(json["data"] as Map<String, Any>)
val printedSchema = SchemaPrinter().print(schema)
val schemaProvider = StringReader(printedSchema)
val parser = SchemaParser()
val schemaGenerator = SchemaGenerator()
val typeRegistry = parser.parse(schemaProvider)
val graphqlSchema = schemaGenerator.makeExecutableSchema(typeRegistry, RuntimeWiring.newRuntimeWiring().build())
Above is the code, and this throws error at SchemaPrinter().print(schema)
.
After some investigation, it turned out that the schema.json seems to be not compliant with what graphql-java expects.
So here’s the definition of RepositoryAffiliation.
{
"kind": "ENUM",
"name": "RepositoryAffiliation",
"description": "The affiliation of a user to a repository",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "OWNER",
"description": "Repositories that are owned by the authenticated user.",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "COLLABORATOR",
"description": "Repositories that the user has been added to as a collaborator.",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ORGANIZATION_MEMBER",
"description": "Repositories that the user has access to through being a member of an organization. This includes every repository on every team that the user is on.",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
and here’s an one of the usage of this enum.
{
"name": "affiliations",
"description": "Array of viewer's affiliation options for repositories returned from the connection. For example, OWNER will include only repositories that the current viewer owns.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "RepositoryAffiliation",
"ofType": null
}
},
"defaultValue": "[\"OWNER\", \"COLLABORATOR\"]"
},
So If I remove \"
from defaultValue
, it seems to work. But it is the output of api and modifying this every time is not good.
Is this an intended behavior or something that graphql-java should fix? It would be great if graphql-java can handle this situation.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Thanks for that. This helped me find a second set of bugs in this arena.
@yshrsmz thanks for getting back!