Skip to content

Commit

Permalink
docs: remove client part of the docs
Browse files Browse the repository at this point in the history
This is moved to a different project: https://github.com/BeatsuDev/simple-gql
  • Loading branch information
BeatsuDev authored Sep 15, 2024
1 parent 59c9333 commit ce919dc
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
```

0 comments on commit ce919dc

Please sign in to comment.