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

Using enums as argument default values is broken on InterfaceType #995

Closed
dkbarn opened this issue Dec 16, 2022 · 8 comments
Closed

Using enums as argument default values is broken on InterfaceType #995

dkbarn opened this issue Dec 16, 2022 · 8 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@dkbarn
Copy link
Contributor

dkbarn commented Dec 16, 2022

Similar to #547 but this bug is specific to type "interface". It seems that if you try to define a schema in which an interface type contains an enum argument with a default value, an error will be thrown when trying to execute an introspection query. This is with:

ariadne 0.16.1
graphql-core 3.2.3

Example:

import enum
import ariadne

type_defs = """
    type Query {
        users: [User!]!
    }

    enum Role {
        ADMIN
        USER
    }

    interface User {
        name(role: Role! = USER): String!
    }
"""

QueryGraphQLType = ariadne.QueryType()

class Role(enum.Enum):
    ADMIN = "ADMIN"
    USER = "USER"

RoleGraphQLType = ariadne.EnumType("Role", Role)

UserGraphQLType = ariadne.InterfaceType("User")

schema = ariadne.make_executable_schema(
    type_defs,
    QueryGraphQLType,
    RoleGraphQLType,
    UserGraphQLType,
)

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

result = ariadne.graphql_sync(schema, {"query": query}, debug=True)
import pprint
pprint.pprint(result)

Error:

Enum 'Role' cannot represent value: 'USER'

GraphQL request:1:44
1 | {__schema{types{name,fields{name,args{name,defaultValue}}}}}
  |                                            ^
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/graphql/execution/execute.py", line 521, in execute_field
    result = resolve_fn(source, info, **args)
  File "/venv/lib/python3.8/site-packages/graphql/type/introspection.py", line 485, in default_value
    value_ast = ast_from_value(item[1].default_value, item[1].type)
  File "/venv/lib/python3.8/site-packages/graphql/utilities/ast_from_value.py", line 63, in ast_from_value
    ast_value = ast_from_value(value, type_.of_type)
  File "/venv/lib/python3.8/site-packages/graphql/utilities/ast_from_value.py", line 108, in ast_from_value
    serialized = type_.serialize(value)  # type: ignore
  File "/venv/lib/python3.8/site-packages/graphql/type/definition.py", line 1233, in serialize
    raise GraphQLError(
graphql.error.graphql_error.GraphQLError: Enum 'Role' cannot represent value: 'USER'
@rafalp
Copy link
Contributor

rafalp commented Dec 16, 2022

From traceback it seems that this is an issue with graphql-core and not with Ariadne?

@dkbarn
Copy link
Contributor Author

dkbarn commented Dec 16, 2022

It's not clear to me which library is at fault, the exception being raised is in the exact same function of graphql-core as #547 and that particular issue was patched in ariadne, so I thought maybe that patch was missing this edge case.

@rafalp
Copy link
Contributor

rafalp commented Dec 16, 2022

Right, it may be as simple fix as adding Interface path to our enums fixer.

@rafalp rafalp added the bug Something isn't working label Dec 16, 2022
@rafalp
Copy link
Contributor

rafalp commented Dec 16, 2022

That seems to have fixed it. It's not likely for proper bugfix release because I have like 4 workhours left in this year before going for vacation, but I'll release 0.17.1 beta with the fix to let you test if my changes will solve this for you, @dkbarn

@dkbarn
Copy link
Contributor Author

dkbarn commented Dec 16, 2022

That would be great if you could put out a beta, thanks!

@rafalp rafalp self-assigned this Dec 16, 2022
@rafalp
Copy link
Contributor

rafalp commented Dec 16, 2022

Released fix in Ariadne 0.17.1b1. I'll keep this task open and on me so I remember to do a proper release in January when I'm back in the office.

@dkbarn
Copy link
Contributor Author

dkbarn commented Dec 16, 2022

Confirmed that 0.17.1b1 resolves the issue. Many thanks! Will look forward to a proper release in the new year.

@rafalp rafalp added this to the Ariadne 0.17 milestone Jan 9, 2023
@rafalp
Copy link
Contributor

rafalp commented Jan 9, 2023

0.17.1 released, moving on to making announcements.

@rafalp rafalp closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants