graphql-python / graphene-federation

Federation implementation for Graphene.
MIT License
40 stars 10 forks source link

Applying @shareable after @key fails, but not vice versa #17

Open Meemaw opened 1 year ago

Meemaw commented 1 year ago

This fails:

@shareable
@key(fields: "id")
class X:
   pass

But this works:

@key(fields: "id")
@shareable
class X:
   pass
erikwrede commented 1 year ago

Hey, sorry for the late reply on this. I cannot reproduce your error with the following MWE:

from graphene_federation import shareable
from graphene_federation.entity import key
from graphene_federation.main import build_schema

def test_multiple_keys_share():
    @shareable
    @key(fields="identifier")
    class User(ObjectType):
        identifier = ID()
        email = String()

    class Query(ObjectType):
        user = Field(User)

    schema = build_schema(query=Query, enable_federation_2=True)
    print(str(schema))

If I instead use pass for the object type or don't extend the objecttype class, I get an exception regardless of the order of @key/@shared. But that's expected behavior. Can you share any additional context or a minimal example so I can have a closer look? ☺️