Skip to content

Introspection isn't generating standard-compliant schema #940

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
arielnmz opened this issue Apr 12, 2019 · 6 comments
Closed

Introspection isn't generating standard-compliant schema #940

arielnmz opened this issue Apr 12, 2019 · 6 comments
Assignees
Labels

Comments

@arielnmz
Copy link

arielnmz commented Apr 12, 2019

Related: JetBrains/js-graphql-intellij-plugin#229

Apparently, the introspection is not returning a compliant schema, breaking the before mentioned project's functionality.

Also related: #877

@ekampf
Copy link
Contributor

ekampf commented Apr 12, 2019

How is #877 related?
Whats the schema in compliance?
need more info here...

@ekampf
Copy link
Contributor

ekampf commented Apr 12, 2019

Please provide example of what's wrong in the schema (expected value vs. what graphene generates)

@jimkyndemeyer
Copy link

Hi Eran.

The issue is how default enum values are serialized in the introspection query response.

The GitHub API has the same problem where it also deviates from the spec. Here's the bug report that I sent to them earlier:

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\"]"

I hope that provides enough information. I'm not familiar with python or graphene, but the schema that would reproduce this looks something like:

enum Episode {
  JEDI,
  EMPIRE
}

type Query {
  heroName(episode: Episode = JEDI): String
}

The introspection result would then return a defaultValue for the episode argument that is "JEDI" instead of simply JEDI.

Best regards,
Jim.

@ekampf
Copy link
Contributor

ekampf commented Apr 12, 2019

Seems like this related to #756
I'll try to have a look

@ekampf
Copy link
Contributor

ekampf commented Apr 12, 2019

@arielnmz @jimkyndemeyer so per @avivey note on issue #877 , the problem is not that graphene generates the wrong schema but that its handling of Python Enums is awkward.

This should still generate a valid schema (but you have to remember to use .name):

desc2 = graphene.String(
        v=graphene.Argument(Episode, default_value=Episode.NEWHOPE.name),
        description='Default value is correct in schema doc. awkward to write.')

We have a PR in the works to better handle Enums, but as this is a breaking change its not an easy change to introduce and we're trying to figure out the best way to introduce it as a "feature flag" you'll need to explicitly turn on.

Follow this PR for updates: #879

@stale
Copy link

stale bot commented Jul 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

3 participants