mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-14 05:36:45 +03:00
7dd8305bdf
Changed in https://github.com/graphql-python/graphql-core/pull/185 , the docs here were out of date, as were the tests.
36 lines
698 B
Python
36 lines
698 B
Python
import graphene
|
|
|
|
|
|
class User(graphene.ObjectType):
|
|
id = graphene.ID()
|
|
name = graphene.String()
|
|
|
|
|
|
class Query(graphene.ObjectType):
|
|
me = graphene.Field(User)
|
|
|
|
def resolve_me(self, info):
|
|
return info.context["user"]
|
|
|
|
|
|
schema = graphene.Schema(query=Query)
|
|
query = """
|
|
query something{
|
|
me {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
"""
|
|
|
|
|
|
def test_query():
|
|
result = schema.execute(query, context={"user": User(id="1", name="Syrus")})
|
|
assert not result.errors
|
|
assert result.data == {"me": {"id": "1", "name": "Syrus"}}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
result = schema.execute(query, context={"user": User(id="X", name="Console")})
|
|
print(result.data["me"])
|