Skip to main content

Quick Example

This NodeJS project shows how to run a query against the Legalesign GraphQL API. We've made every effort to keep this code as simple as possible so that you can bring it into your own projects without difficulty.

Requirements

To run this project you will need:

  • To have registered for an account at https://www.legalesign.com
  • Installed a recent version of NodeJS onto your test machine
  • Installed the Git command line tools (if you intend to setup the project from Git)

Setup

Download the example project on to your test machine. The easiest way to do this is to clone the github project. In your projects folder run the following command from the terminal or shell:

git clone https://github.com/legalesign/legalesign-graphql-tutorial.git

Change directory into the project folder.

cd legalesign-node-tutorial

Install the required packages for this project. Note: in this project we are using the lightweight graphql-request library, this is optional and you can use any other client you want.

npm install

Alter the code

Open userInformation.js and change line 12 to include your credentials. You can do this using your choice of developer tools, such as VS Code or Eclipse, or just a trusty text editor. It should look something like this;

const client = new GraphQLClient(
"https://7hfrjecmwjgehp3q2d3c2fbi6m.appsync-api.eu-west-2.amazonaws.com/graphql",
{ headers: {'Authorization': await getToken("me@yourcorp.com", "password")} }
);

When used in production you will want to extract these credentials from a safe store or environment.

Run the code

From the command line you can test the user information query by entering the following command;

node userInformation.js

Or you can run the sample code direcly from VS Code (if that's your IDE) as the launch.json has been provided. You should see something similar to the output given below:

{
user: {
id: 'dXNyM2U5NjQwOTMtNTMzZi00MTdlLWEyYzMtZGNmMWM4M2U5N2Ux',
name: 'Api Tester',
email: 'api.test@legalesign.com',
memberConnection: { groupMembers: [Array] }
}
}

We haven't formatted the answer but if you print out all of the JSON using stringify() or just debug the code, you'll see that all the groups that you're a member of are included in the groupMember array.