Skip to content

Examples

To better show you what you can do once you have a suitable backend, I've created a few examples.

These examples are all based on the official SWAPI GraphQL API.

Query a film by id

from qlient.core import GraphQLResponse, Client

client = Client(...)

response: GraphQLResponse = client.query.film(id="ZmlsbXM6MQ==")

print(response.request.query)
(Which automatically selects fields and generates the following query)
query film($id: ID) {
    film(id: $id) {
        title
        episodeID
        openingCrawl
        director
        producers
        releaseDate
        speciesConnection {
            totalCount
        }
        starshipConnection {
            totalCount
        }
        vehicleConnection {
            totalCount
        }
        characterConnection {
            totalCount
        }
        planetConnection {
            totalCount
        }
        created
        edited
        id
    }
}

Query all films with selection

from qlient.core import GraphQLResponse, Fields, Client

client = Client(...)

response: GraphQLResponse = client.query.allFilms(
    Fields("totalCount", films=["id", "title", "director", "releaseDate"])
)

print(response.request.query)
(Which generates the following query)
query allFilms {
    allFilms {
        totalCount
        films {
            id
            title
            director
            releaseDate
        }
    }
}