Skip to content

getcrft/appsync-gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Appsync API Gateway

Utility method for making API calls to AppSync from Lambdas in AWS.

This library essentially implements the suggested approach outlined by AWS Amplify Docs in a nice package.

Usage

Install via NPM:

npm i @getcrft/appsync-gateway --save

then use like:

const {
  GraphQLGateway,
  IAMCredentialsStrategy,
  APIKeyCredentialsStrategy,
  AuthHeaderCredentialsStrategy
} = require('@getcrft/appsync-gateway');

// IAM Mode
const creds = new IAMCredentialsStrategy();

// API Key Mode
const creds = new APIKeyCredentialsStrategy(API_KEY);

// Auth Headers Mode
const creds = new AuthHeaderCredentialsStrategy(authHeader);

const gateway = new GraphQLGateway(
  creds,
  process.env.API_API_GRAPHQLAPIENDPOINTOUTPUT
);

const myQuery = `
  query ListTodosOperation {
    listTodos {
      items {
        title
      }
    }
  }
`;

await gateway.runQuery({
  operationName: 'ListTodosOperation',
  query: myQuery,
  variables: {
    input: {}
  }
});

Commands

  • npm build - Run the typescript build