Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Feb 25, 2019 · 13 comments

Comments

@ghost
Copy link

ghost commented Feb 25, 2019

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}"
}
}
}
}
}

@ghost
Copy link
Author

ghost commented Feb 25, 2019

Attached fetched shema:__schema.json.zip

@jimkyndemeyer
Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented Mar 5, 2019

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

jimkyndemeyer added a commit that referenced this issue Mar 9, 2019
- Strip out emojis from response JSON to be able to use the GitHub v4 schema
- Added configuration option to skip default values in case they aren't spec compliant
jimkyndemeyer added a commit that referenced this issue Mar 10, 2019
…#217)

- Added support for custom scalars in introspection schema builder
- Ensured proper escaping of description string as outlined in spec
- Added retry introspection action and suggestion to skip defaultValues if they're non-spec
@jimkyndemeyer
Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented Mar 10, 2019

@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

@ghost
Copy link
Author

ghost commented Mar 10, 2019

@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

@jimkyndemeyer
Copy link
Collaborator

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.

@jimkyndemeyer jimkyndemeyer reopened this Mar 10, 2019
@jimkyndemeyer
Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented Mar 14, 2019

@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

@jimkyndemeyer
Copy link
Collaborator

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

@jimkyndemeyer
Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented Apr 8, 2019

@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.

@jimkyndemeyer
Copy link
Collaborator

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant