Skip to content

[Question] Why are enum values accepted when passed as variables but not in query strings? #110

@Ambro17

Description

@Ambro17

Intro

I have a doubt about a current implementation choice of graphql over http.

Problem

Enum values are not accepted when passed along the query. But they are accepted when parametrized and passed as variables

Example

This doesn't work

{
	field(enum_arg: "ENUM_VALUE") {
		another_field
	}
}

Assuming enum_arg has an graphql enum type and ENUM_VALUE is a valide Enum.name for the given python Enum sublcass.

But this apparently equivalent example does work

query MyQuery($arg: ArgType!) {
	field(enum_arg: $arg) {
		another_field
	}
}

with variables :

{
	"arg": "ENUM_VALUE"
}

does work.

Additional details

I went down and explore graphql-core source code and this is expected behaviour and it also has a test at https://github.com/graphql-python/graphql-core/blob/master/tests/type/test_enum.py#L257-L270
So i'm now sure this is expected behaviour.
Now my question is why is this the expected behaviour?
Is there any graphql/python concept that i am missing that explains this?

Thanks in advance for your effort writing and maintaining graphql-core!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions