Skip to content

Examples

This page contains examples from the official swapi-graphql.

Query all Films

Say you want to list all films on the endpoint.

query {
  allFilms {
    totalCount
    films {
      id
      title
      director
      releaseDate
    }
  }
}

The corresponding code looks like this:

from qlient.http import HTTPClient, Fields

client = HTTPClient("https://swapi-graphql.netlify.app/.netlify/functions/index")

all_films_fields = Fields(
    "totalCount", films=["id", "title", "director", "releaseDate"]
)

response = client.query.allFilms(all_films_fields)

(This example is complete and should run "as is".)

Query film by id

Now you've got an id and want the information for that movie.

query film($id: ID) {
    film(id: $id) {
        id
        title
        episodeID
        director
        releaseDate
    }
}

The corresponding code looks like this:

from qlient.http import HTTPClient

client = HTTPClient("https://swapi-graphql.netlify.app/.netlify/functions/index")

response = client.query.allFilms(
    ["id", "title", "episodeID", "director", "releaseDate"],
    id="ZmlsbXM6MQ==",
)

(This example is complete and should run "as is".)