GraphQL Schema

Traditionally, while implementing a GraphQL backend, you need to define your schema, types and fields. However, in case of Hasura, you just have to create tables and everything else is automatically generated.

Accessing the schema

To get your GraphQL schema:

  1. Go to the API-Explorer.

  2. Go to the JSON Raw section on the left.

  3. Add your admin token to the headers and make a GET request to:

    GET https://data.<cluster-name>.hasura-app.io/v1alpha1/graphql/schema HTTP/1.1
    Authorization: Bearer <token>
    
  4. Hit send

    ../../../../_images/graphql-get-schema.png

Using the community tooling around the schema

  • Apollo codegen

    As we don’t yet support introspection over the graphql endpoint, the standard tooling (apollo-codegen) to generate schema.json will not work out of the box. You’ll need to run an additional command to fetch the schema as follows:

    $ curl -H 'Authorization: Bearer <auth-token>' 'https://data.<cluster-name>.hasura-app.io/v1alpha1/graphql/schema' | jq -r '.schema' > schema.graphql
    

    Now that you have the GraphQL schema, you can generate schema.json as follows:

    $ apollo-codegen introspect-schema schema.graphql --output schema.json
    
  • ESLint: Check this guide for using your schema to set up ESLint.