Skip to content

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

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

Closed
the-papi opened this issue Mar 29, 2021 · 2 comments
Closed

Comments

@the-papi
Copy link

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).

@Cito Cito closed this as completed in 3403e1a Mar 29, 2021
@Cito
Copy link
Member

Cito commented Mar 29, 2021

Thanks a lot for reporting this. Should be fixed in the main branch now.

@Cito
Copy link
Member

Cito commented Apr 8, 2021

Fix has now been released in v3.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants