Since the Transitland released its new and shiny GraphQL API, it is possible to query the API using GraphQL.
The client is being built using GenQL and updated hourly, if there are upstream changes.
First add the library and its peerDependency to your project:
-
npm
npm i @ioki/transitland-gql-client@latest
-
yarn
yarn add @ioki/transitland-gql-client@latest
- Get an API key with access to the gql api at transit.land
- Create a client instance:
import { createClient } from '@ioki/transitland-gql-client';
const transitlandClient = createClient({
apiKey: "YOUR_SUPER_SECRET_API_KEY",
fetch: fetchClient // not needed for browser and node >= v18 (and >=v16 with --experimental-fetch)
});
GenQL provides a neat converter from GraphQL to TypeScript. So you can actually just test the queries you want to use in the playground.
Using GraphQL's strict type definitions, it is pretty easy to generate a mock server you could use during your tests. An extensive example is stored as a test.
Distributed under the MIT License. See LICENSE.md
for more information.
- join us @ioki and make this one of your projects
- create issues and pull requests, we're happy to enhance this
ioki Mobility - @ioki_mobility
Project Link: https://github.com/ioki-mobility/transitland-gql-client