Skip to content
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

Enum cannot represent value, when querying for defaultValue #126

Closed
dkbarn opened this issue Apr 8, 2021 · 5 comments
Closed

Enum cannot represent value, when querying for defaultValue #126

dkbarn opened this issue Apr 8, 2021 · 5 comments

Comments

@dkbarn
Copy link

dkbarn commented Apr 8, 2021

I'm using ariadne and suddenly started encountering an error from the introspection query issued by GraphQL Playground when I upgraded from ariadne 0.12.0 to 0.13.0.

I've boiled the problem down as simply as possible and actually it seems to have nothing to do with ariadne, but instead is a change in behaviour from graphql-core 3.0 -> 3.1.

The following works in graphql-core 3.0, but not in 3.1:

import graphql
import pprint

schema = graphql.build_schema("""
    enum Role {
        ADMIN
        USER
    }

    type Query {
        hello(r: Role = USER): String
    }
""")

query = "{__schema{types{name,fields{name,args{name,defaultValue}}}}}"

result = graphql.graphql_sync(schema, query)

pprint.pprint(result)

In graphql-core 3.1, it throws the error: Enum 'Role' cannot represent value: 'USER'

Could someone tell me if I'm doing something wrong? Have I been making an incorrect assumption which errorneously passed in 3.0 and has now been "fixed"? Or is this a regression?

@Cito
Copy link
Member

Cito commented Apr 8, 2021

Thanks for reporting. I think this is the same problem as #125, and has been fixed already in the main branch.

@Cito
Copy link
Member

Cito commented Apr 8, 2021

Fix has now been released in v3.1.4.

@Cito Cito closed this as completed Apr 8, 2021
@bnaoki
Copy link

bnaoki commented Apr 8, 2021

Hi @Cito, I upgraded graphql-core from v3.1.3 to v3.1.4 just now but seem to still run into this same issue.

I have something very similar to what @dkbarn reported except that my argument is non-nullable.

enum ArchivedFilter {
  ARCHIVED
  NON_ARCHIVED
  ALL
}

type Query {
  entity(archived: ArchivedFilter! = NON_ARCHIVED): [Entity]
}

Getting the following error:

File ".../lib/python3.9/site-packages/graphql/type/definition.py", line 1146, in serialize
     raise GraphQLError(
 graphql.error.graphql_error.GraphQLError: Enum 'ArchivedFilter' cannot represent value: 'NON_ARCHIVED'

FWIW, I'm also using ariadne.

@dkbarn
Copy link
Author

dkbarn commented Apr 9, 2021

@bnaoki do you still get the error message if you completely remove ariadne from the equation? I took my code snippet above and changed the default value to be non-nullable, and the error goes away with graphql-core 3.1.4.

I think the problem might be in ariadne now. Even after upgrading to graphql-core 3.1.4, I still get the error you're seeing when I have an enum as a default argument value in my SDL. But I think this is because ariadne does not properly support this case yet. See: mirumee/ariadne#293

For the time being I've had to remove these default values from my schema to make ariadne 0.13.0 happy.

@bnaoki
Copy link

bnaoki commented Apr 9, 2021

Ahh, you're right. It does seem to be an issue with ariadne. Thanks for this info!

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

3 participants