Skip to content

Enum default_value serialization issue #166

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

Open
nikordaris opened this issue Mar 20, 2018 · 4 comments
Open

Enum default_value serialization issue #166

nikordaris opened this issue Mar 20, 2018 · 4 comments

Comments

@nikordaris
Copy link

Originally reported in graphene issue #691

Argument default_value serializes enum value instead of name. graphql spec does not support enum values and graphql-js serializes enums to the name not value. graphql-python is not consistent with graphql-js. I attempted to find a workaround by setting the enum value to a string of the name but teh result is a string that includes escaped quotes.

Using the name of the enum doesn't work:

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

Using a string value doesn't work either:

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

@yywing
Copy link

yywing commented Jun 26, 2018

Any progress??

@nikordaris
Copy link
Author

I haven't tried looking through the source again to try to figure it out. I just stopped using default_value for enums. Which sucks but not currently critical for my projects. I hope this issue can get some love from someone

@MichaelAquilina
Copy link

I'm also affected by this. Using default values with Enums currently breaks introspection with our client library (in our case we use Apollo).

Is there a suggested work around for this?

@japrogramer
Copy link

@MichaelAquilina I would give it a default value in the resolver,

input.get('my_enum', MyEnum.FOO.value)

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

4 participants