diff --git a/README.md b/README.md index 92ea148..d36d4e7 100644 --- a/README.md +++ b/README.md @@ -109,77 +109,3 @@ print(Character) # } # ``` - -Interacting with a GraphQL endpoint: - -```py -import gqlrequests -import asyncio - -# Normal query -gqlclient = gqlrequests.Client( - api_endpoint="api.example.com/gql", - authorization="abcdefghijklmnopqrstuvwxyz" -) - -schema, types = gqlclient.introspect() -character_search_query = types.Character(func_name="findCharacter") - -character = gqlclient.execute(character_search_query(name="Luke").build()) -print(character.name) - -# Asynchronous queries -RootQuery = schema.RootQuery -async def main(): - gqlclient = gqlrequests.AsyncClient( - api_endpoint="api.example.com/gql", - authorization="abcdefghijklmnopqrstuvwxyz" - ) - - queries = asyncio.gather( - gqlclient.execute(RootQuery(fields=["character"]).build()), - gqlclient.execute(RootQuery(fields=["episode"]).build()) - ) - - # Returns pydantic Models - character, episode = await queries - - # Or simply: - character = await gqlclient.execute(RootQuery().build()) - -asyncio.run(main()) -``` - -```py -"""Subscribing to a graphql websocket""" -import gqlrequests -import asyncio - -schema, types = gqlrequests.introspect() -RootMutation = schema.RootMutation - - -# Example of how the type of RootMutation.live could look like: -# -# class LiveViewers(gqlrequests.QueryBuilder): -# viewers: int -# measurementTimeUnix: int - - -async def main(): - gqlclient = gqlrequests.Client( - api_endpoint="api.example.com/gql", - authorization="abcdefghijklmnopqrstuvwxyz" - ) - - query_string = RootMutation(fields=["live"]).build() - - async with gqlclient.subscribe(query_string) as subscription: - async for data in subscription: - assert isinstance(data, LiveViewers) - - print(data.viewers, data.measurementTimeUnix) - if data.viewers < 10: break - -asyncio.run(main()) -```