Skip to content

The same directive on the same enum value in multiple enums causes TypeError #125

Closed
@the-papi

Description

@the-papi

When i try to define several different enums that share some of their values with the same directives, then I get TypeError.

Code to reproduce:

from graphql import parse, build_ast_schema
build_ast_schema(parse('''
    directive @myDirective on ENUM_VALUE

    enum MyEnum {
        MY_VALUE @myDirective
    }

    enum MyEnum2 {
        MY_VALUE @myDirective
    }

    type Query { foobar: Boolean }
'''))

Output:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-88196fa4e5fd> in <module>
      1 from graphql import parse, build_ast_schema
----> 2 build_ast_schema(parse('''
      3     directive @myDirective on ENUM_VALUE
      4 
      5     enum MyEnum {

/usr/lib/python3.9/site-packages/graphql/utilities/build_ast_schema.py in build_ast_schema(document_ast, assume_valid, assume_valid_sdl)
     47         from ..validation.validate import assert_valid_sdl
     48 
---> 49         assert_valid_sdl(document_ast)
     50 
     51     schema_kwargs = extend_schema_impl(empty_schema_config, document_ast, assume_valid)

/usr/lib/python3.9/site-packages/graphql/validation/validate.py in assert_valid_sdl(document_ast)
    112     errors = validate_sdl(document_ast)
    113     if errors:
--> 114         raise TypeError("\n\n".join(error.message for error in errors))
    115 
    116 

TypeError: The directive '@myDirective' can only be used once at this location.

Expected output:

<graphql.type.schema.GraphQLSchema at 0x7fb721122550>

I found that this bug is introduced in graphql-core 3.1.0b1 (3.1.0b0 works fine).

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