Skip to content

Enum default_value serialization issue #691

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
nikordaris opened this issue Mar 19, 2018 · 6 comments
Closed

Enum default_value serialization issue #691

nikordaris opened this issue Mar 19, 2018 · 6 comments

Comments

@nikordaris
Copy link
Contributor

nikordaris commented Mar 19, 2018

Using graphene 2.0.1

class MyEnum(graphene.Enum):
    FOO=0
    BAR=1

foobar = graphene.List(FooBar, my_enum=graphene.Argument(MyEnum, default_value=MyEnum.FOO.name))

This results in the defaultValue being "\"FOO\"". This does not follow the graphql spec for enums and breaks with third party introspection. Specifically i'm trying to stitch a graphene remote schema and the invalid defaultValue results in a null returned in the merged schema (using graphql-tools).

class MyEnum(graphene.Enum):
    FOO="FOO"
    BAR="BAR"

This also doesn't work with using MyEnum.FOO.value for default_value nor setting it specifically to the string "FOO"

I tried looking for how default_value gets resolved for enums but haven't been able to track it down. I think if we can just get the string value for default_value to not include the escaped string quotes then my schema stitching will work. I haven't been able to figure out how to define an enum so that this will happen.

@jkimbo
Copy link
Member

jkimbo commented Mar 19, 2018

@nikordaris in your first example it should be default_value=MyEnum.FOO.value

@nikordaris
Copy link
Contributor Author

@jkimbo using the value breaks the graphql enum spec. Introspection doesn't provide the value of an enum, only the name. This means that the value is never used once it gets to the client side. By setting the default_value to the enum value, the default_value becomes invalid as input for the enum on the client. This is an oversight of the spec in my opinion but graphql-js implements enum such that serializing the enum grabs the name instead of the value. graphene is not consistent with graphql-js which is considered the standard implementation.

But that is why i tried setting the value to a string that is the same as the name but the parser for default_value for enum's doesn't parse string values correctly for enum. it includes escaped quotes in the value.

@jkimbo
Copy link
Member

jkimbo commented Mar 19, 2018

Looks like you're right, there is an issue with representing the a default value of an Enum in graphiql. The issue is probably in https://github.com/graphql-python/graphql-core which is pretty much a direct port of graphql-js

@nikordaris
Copy link
Contributor Author

Ok, i'll create an issue in graphql-core as well to see what they think about it

@nikordaris
Copy link
Contributor Author

@jkimbo
Copy link
Member

jkimbo commented Mar 20, 2018

Thanks @nikolas , I'm going to close this issue in favour of the one in the graphql-core repo.

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

2 participants