Graphene: Introspection isn't generating standard-compliant schema

Created on 12 Apr 2019  路  6Comments  路  Source: graphql-python/graphene

Related: https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/issues/229

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

Also related: https://github.com/graphql-python/graphene/issues/877

wontfix

Most helpful comment

@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: https://github.com/graphql-python/graphene/pull/879

All 6 comments

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

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

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.

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

@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: https://github.com/graphql-python/graphene/pull/879

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Globegitter picture Globegitter  路  4Comments

romaia picture romaia  路  3Comments

junchiz picture junchiz  路  3Comments

jloveric picture jloveric  路  4Comments

tricoder42 picture tricoder42  路  4Comments