Download testbed/graphql-python__graphene/examples/context_example.py from hc99/FEA-Bench: direct link, hf CLI and curl.
- Browser
- Download file 698 Bytes
-
https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/graphql-python__graphene/examples/context_example.py
- Command line
-
hf download hf://datasets/hc99/FEA-Bench/testbed/graphql-python__graphene/examples/context_example.py
-
curl -L -o context_example.py https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/graphql-python__graphene/examples/context_example.py
698 Bytes
| import graphene | |
| class User(graphene.ObjectType): | |
| id = graphene.ID() | |
| name = graphene.String() | |
| class Query(graphene.ObjectType): | |
| me = graphene.Field(User) | |
| def resolve_me(root, 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"]) | |