Js-graphql-intellij-plugin: [v2] GitHub v4 - Internal error: should never happen: cannot build value of UserStatusOrderField from StringValue{value='UPDATED_AT'}

Created on 25 Feb 2019  路  13Comments  路  Source: jimkyndemeyer/js-graphql-intellij-plugin

GraphQL Introspection Error
Internal error: should never happen: cannot build value of UserStatusOrderField from StringValue{value='UPDATED_AT'}

Plugin: v2.0.0-alpha-6

{
"name": "GitHub v4 Schema",
"schemaPath": "graphql.schema.json",
"extensions": {
"endpoints": {
"GitHub": {
"url": "https://api.github.com/graphql",
"headers": {
"Authorization": "Bearer ${env:YOUR_GITHUB_ACCESS_TOKEN}"
}
}
}
}
}

All 13 comments

Attached fetched shema:__schema.json.zip

Hi Daniel.

Thanks for helping with the test of v2 alpha.

I've dug into this, and it appears that the GitHub GraphQL API returns an introspection query result that isn't fully compliant with the GraphQL specification, and that graphql-java which this plugin relies on, is right to throw an error.

I've contacted GitHub support to try and get this resolved as follows:

Hi GitHub.

First of all, thanks for being part of the GraphQL community.

I'm the lead developer of js-graphql-intellij-plugin, a GraphQL plugin for the IntelliJ Platform. The goal with the plugin is to create a great developer experience when working with GraphQL.

One of the core use cases is to introspect endpoints such as your GraphQL API to provide schema-aware completion and error reporting in the IDE.

As part of that work I've come across a few issues where your endpoint doesn't fully adhere to the GraphQL specification. The result is that graphql-java, which the plugin uses under the hood, rightly throws validation and parse errors when it has to build up a schema based on the introspection query result.

I've come across the following issues:

__Introspection serialization of enums in default values for arguments__

It appears that you serialize default enum values as quoted strings in lists and input objects. The specification (https://facebook.github.io/graphql/June2018/#sec-The-__InputValue-Type) states that:

"defaultValue may return a String encoding (using the __GraphQL language__) of the default value used by this input value in the condition a value is not provided at runtime. If this input value has no default value, returns null."

In the GraphQL grammar the enum values are unquoted, e.g. ENUM_VALUE and not "ENUM_VALUE".

Examples from your schema:

The "orderBy" argument on a number of fields is returned as:

"defaultValue": "{field:\"UPDATED_AT\",direction:\"DESC\"}"

The spec compliant default value should be encoded as a GraphQL Language input object:

"defaultValue": "{field: UPDATED_AT, direction: DESC}"

If the enum values are quoted, a GraphQL lexer such as the one in graphql-java detects a string token instead of an enum value token, which ultimately results in a schema validation error when an enum value is expected.

The issue also appears for lists of enums, e.g. in the "affiliations" argument:

"defaultValue": "[\"OWNER\", \"COLLABORATOR\"]"

__Schema descriptions: Use of unicode ranges not allowed by the GraphQL grammar__

The "ReactionContent" enum values have descriptions that include emojis:

{"name": "THUMBS_UP", "description": "Represents the 馃憤 emoji."}

According to the spec, GraphQL limits the allowed unicode ranges: https://facebook.github.io/graphql/June2018/#sec-Source-Text

In the introspection use I mentioned, this description is translated into a single or triple quoted description when epxressed as GraphQL SDL, but the graphql-java lexer then rightly complains that it has encountered an invalid token.

I hope that you can address these issues to ensure optimal integration with the tooling eco-system. It would really help the developer experience for WebStorm/IntelliJ users that work with your GraphQL API.

Thanks,
Jim.

I've attached a fixed version of their schema as SDL which should allow you to work with their API until this gets resolved.

github-schema-fixed.zip

Best regards,
Jim.

@jimkyndemeyer
thank you very much!
local schema works perfectly!

The upcoming alpha-8 which I'll release later today does two things to address the non-spec introspection result:

  • It sanitizes the JSON to ignore unicode characters outside the range allowed in the GraphQL spec. This fixes the reaction emojis that prevent a valid schema from being built
  • The plugin can now ignore invalid defaultValues and suggests turning them off if building a valid schema fails.

With that developers should be able to work with the GitHub endpoint, although GitHub needs to be spec-compliant before the defaultValues can be shown by this plugin.

@jimkyndemeyer Hi, I'm testing alpha-8 with GitHub's endpoint...

The first time an option with Retry without Default Values works well.
But then, I did a refresh again and now only shows "There is no top level...."

Please, review attached screen:

image

@jimkyndemeyer I found the issue... is related to the use of folder in schemaPath:

works well: "schemaPath": "github.schema.json",
Doesn't work: "schemaPath": ".graphql/github.schema.json",

.graphql is a folder in root folder

Thanks, I'll take a look at how it writes the result to the virtual file system.

Note that you can use the .graphql extension in your schemaPath if you prefer the schema to be written to disk as GraphQL schema language (SDL). This is also more efficient as the plugin only has to translate the JSON to SDL once when it writes to disk.

Hi Daniel.

I tried reproducing based on the steps you outlined:

  • "schemaPath": ".graphql/github.schema.json"
  • Introspect
  • New .graphql folder and schema JSON file is created
  • Get the spec compliance error, use "Retry without default values" action
  • Rune Introspect again and observe schema types found

But the schema types are discovered as expected. Can you reliably reproduce the issue, and provide additional info to help reproduce this?

Thanks,
Jim.

@jimkyndemeyer hi, yes, attached the screen with the state after click on Retry (skip default values from now on)

v2.0.0-alpha-8

Step 1

After that the preferences are:

Preferences 2019-03-14 15-29-19

Hmm, it's not clear why this doesn't break here when I test it.

For next steps I need to reproduce. Can you create a blank project, copy over your .graphqlconfigand verify that the problem persists. In that case please attach a zip of that new minimal project to this issue.

__Note!__: Take care that you don't include your github token. That should be referenced from your config via an environment variable

Hi Daniel.

I'm closing this based on being unable to reproduce the issue. If you find the time to create a repository which demonstrates the issue, then feel free to link to it here and I'll reopen.

Best regards,
Jim.

@jimkyndemeyer

I found the solution for the issue "There is no top level...."

The schemaPath ".graphql/xxxxx" was marked as "Excluded" in WebStorm... :)

I removed the exclusion and now works!

Regards,
Daniel.

Just got word from the GitHub dev team that they fixed the non-spec issues in their schema. I just introspected it using the plugin and it validates without errors 馃憤

Was this page helpful?
0 / 5 - 0 ratings