@ttoss/aws-appsync-nodejs

1.8.5 • Public • Published

@ttoss/aws-appsync-nodejs

This package implements a AWS AppSync client for Node.js. We've followed the AWS Amplify example to create this package.

Installation

pnpm add @ttoss/aws-appsync-nodejs

Quickstart

import { appSyncClient } from '@ttoss/aws-appsync-nodejs';

appSyncClient.setConfig({
  endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
  apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
});

const query = /* GraphQL */ `
  query user($id: ID!) {
    user(id: $id) {
      id
      name
    }
  }
`;

appSyncClient.query(query, { id: '1' }).then((result) => {
  console.log(result);
});

Config

You need to configure the client with endpoint (required), apiKey (optional) and credentials (optional).

  1. If you don't provide apiKey or credentials, the client will try to use the AWS credentials from the environment variables of your system—local computer, AWS Lambda, EC2.
appSyncClient.setConfig({
  endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
});
  1. If you provide apiKey, the client will use the API key to authenticate.
appSyncClient.setConfig({
  endpoint: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
  apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
});
  1. If you provide credentials, the client will use the credentials to authenticate.
appSyncClient.setConfig({
  endpoint,
  credentials: {
    accessKeyId: // access key id,
    secretAccessKey: // secret access key,
    sessionToken: // optional session token,
  },
});

If you provide the default endpoint (https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql), the client will retrieve the region from the endpoint. If you provide the endpoint with the custom domain (https://custom-domain.com), you need to provide the region as well.

appSyncClient.setConfig({
  endpoint: 'https://custom-domain.com',
  region: 'us-east-1',
  credentials: {
    accessKeyId: // access key id,
    secretAccessKey: // secret access key,
    sessionToken: // optional session token,
  },
});

Readme

Keywords

none

Package Sidebar

Install

npm i @ttoss/aws-appsync-nodejs

Weekly Downloads

61

Version

1.8.5

License

MIT

Unpacked Size

14.4 kB

Total Files

8

Last publish

Collaborators

  • pedro-arantes
  • techtriangulostecnologia