question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception while parsing schema.json

See original GitHub issue

graphql-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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bbakermancommented, May 2, 2019

Thanks for that. This helped me find a second set of bugs in this arena.

0reactions
andimarekcommented, Jul 19, 2019

@yshrsmz thanks for getting back!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Json Schema- Parsing error in Json.NET - Stack Overflow
I am currently facing a problem in parsing my json schema with Json.NET . My schema is composed by an array, whose items...
Read more >
Raise exception while parsing JSON with the wrong schema on the ...
During JSON parsing, I want to catch an exception for optional sequential files in which schema differed from my case class. Let me...
Read more >
Handling Validation Errors - python-jsonschema
When an invalid instance is encountered, a ValidationError will be raised or returned, depending on which method or function is used. exception jsonschema....
Read more >
ADF data flow cannot parse JSON schema correctly
ADF data flow cannot parse JSON schema correctly: FASTFAIL exception error. Hi everyhwere,. I am using the YouTube Analytics and Reporting ...
Read more >
JSON validation - IBM
The JSON parser offers high-performance, standards-compliant JSON schema validation at any point in a message flow. Validation of the input JSON message or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found