Skip to content

assertion error in ast_from_value during introspection query when providing enum member as default value #756

Closed
@DrPyser

Description

@DrPyser

So I have an InputObjectType with an Enum field, and I want to provide a default value. The enum field is created from a pre-existing python enum:

MyGrapheneEnumType = graphene.Enum.from_enum(
    MyEnumType
)
class MyInput(graphene.InputObjectType):
    my_enum_field = graphene.Field(MyGrapheneEnumType, default_value=MyGrapheneEnumType.MEMBER)

I'm not sure it's the right way to do it(documentation would help), but I don't think an assertion error is the expected result.

If I then do an introspection query(I'm using insomnia which does them automatically), like this one:

query IntrospectionQuery {
      __schema {
        queryType { name }
        mutationType { name }
        subscriptionType { name }
        types {
          ...FullType
        }
        directives {
          name
          description
          locations
          args {
            ...InputValue
          }
        }
      }
    }

    fragment FullType on __Type {
      kind
      name
      description
      fields(includeDeprecated: true) {
        name
        description
        args {
          ...InputValue
        }
        type {
          ...TypeRef
        }
        isDeprecated
        deprecationReason
      }
      inputFields {
        ...InputValue
      }
      interfaces {
        ...TypeRef
      }
      enumValues(includeDeprecated: true) {
        name
        description
        isDeprecated
        deprecationReason
      }
      possibleTypes {
        ...TypeRef
      }
    }

    fragment InputValue on __InputValue {
      name
      description
      type { ...TypeRef }
      defaultValue
    }

    fragment TypeRef on __Type {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
                ofType {
                  kind
                  name
                  ofType {
                    kind
                    name
                  }
                }
              }
            }
          }
        }
      }
    }

I get the following stack trace:

2018-06-05 03:05:09,963 - graphql.execution.executor - ERROR - An error occurred while resolving field __InputValue.defaultValue
Traceback (most recent call last):
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/execution/executor.py", line 311, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/execution/executors/sync.py", line 7, in execute
    return fn(*args, **kwargs)
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/type/introspection.py", line 349, in <lambda>
    else print_ast(ast_from_value(input_val.default_value, input_val))
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/utils/ast_from_value.py", line 49, in ast_from_value
    assert isinstance(value, dict)
AssertionError
Traceback (most recent call last):
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/execution/executor.py", line 330, in complete_value_catching_error
    exe_context, return_type, field_asts, info, result)
  File "/home/drpyser/Documents/python/kioto_rest/.env/lib/python3.6/site-packages/graphql/execution/executor.py", line 383, in complete_value
    raise GraphQLLocatedError(field_asts, original_error=result)
graphql.error.located_error.GraphQLLocatedError

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions