This repo shows how to generate graphql-bindings for Hasura GraphQL Engine generated APIs.
-
Clone the repo and
cd
into it.$ git clone https://github.com/hasura/generate-graphql-bindings && cd generate-graphql-bindings
-
Place your GraphQL schema in the root directory. To generate your GraphQL schema, you can run the following two commands from the root directory:
$ npm install -g get-graphql-schema $ get-graphql-schema GRAPHQL_URL > schema.graphql # replace GRAPHQL_URL with your GraphQL URL such as `https://test.herokuapp.com/v1alpha1/graphql`
If you have set an ACCESS_KEY for the GraphQL engine, you need to pass a header while generating the schema.
-
Set your GraphQL Engine URL in
index.js
as:// replace 'http://tanmai .....' with your GraphQL engine URL const graphqlEndpoint = 'http://tanmai-graphql2.herokuapp.com/v1alpha1/graphql';
-
You can export this binding and start using it. For example:
import HasuraBinding from './bindigs/'; const newBinding = new HasuraBinding(); newBinding.query.article(args, '{ id, title, content }').then((response) => console.log(response));
To know about using GraphQL bindings, read the docs.