question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum cannot represent value, when querying for defaultValue

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dkbarncommented, 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: https://github.com/mirumee/ariadne/issues/293

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

0reactions
bnaokicommented, Apr 9, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enum $EnumName cannot represent non-enum value
I am getting this error message when I run my query that seems contradictory. I've followed the enum example in the documentation pretty...
Read more >
Using enums as argument default values is broken ... - GitHub
The introspection query which is issued by GraphQL Playground throws an error ... GraphQLError: Enum 'Role' cannot represent value: 'USER'.
Read more >
What you need to know about GraphQL enums
The field using an enum type requires an enum reference, so passing the enum value isn't considered valid.
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
If an ENUM column is declared to permit NULL , the NULL value is a valid value for the column, and the default...
Read more >
How to use GraphQL enum and its best practices
The enum class allows us to map enum values to internal values represented by integers (or different strings etc.).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found