Skip to main content

Install the Apollo GraphQL Client

It's worth noting that there are hundreds of graphql clients for Node.JS and Javascript, we've chosen to demonstrate Apollo because it's one of the most used and supports almost every eventuality. Even if you choose a different client, the queries and mutations that we run through here should give you a good idea of how to use it against the Legalesign API.

Let's install the package:

npm install @apollo/client graphql

Create index.js in your project folder and enter the following code:

index.js
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
useQuery,
gql
} from "@apollo/client";

Next we'll initialize the Apollo Client, passing its constructor the Legalesign API domain:

index.js
const awsGraphqlFetch = (uri, options) => {
const token = getJwtToken()
options.headers["Authorization"] = token;
return fetch(uri, options);
};

const client = new ApolloClient({
uri: 'https://graphql.legalesign.com',
cache: new InMemoryCache(),
fetch: awsGraphqlFetch
});

In the same index.js we'll make a query to the API to find out our user, organisation and group details.

index.js
// const client = ...

client
.query({
query: gql`
query User {
id
email
}
`
})
.then(result => console.log(result));

Let's run that. Execute our code by typing the following at the terminal/command prompt.

node index.js

For more information on the Apollo client, check out the web site https://www.apollographql.com/docs/react/.