Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

appsync-client

1.10.0 • Public • Published

Appsync Client

Built withtypescript version dependants license

A lightweight Appsync client that signs requests for you - perfect for running on Lambdas or servers. This module has not been tested for use on the browser.

When using tree-shaking, the impact on your bundle size is just a few kb.

Use

import AppsyncClient from "appsync-client";
 
async function getTodo() {
 
    // Create a client
    const client = new AppsyncClient({
        // Required
        apiUrl: "https://xxx.appsync-api.xx-xxxx-x.amazonaws.com/graphql",
        // Optional - these will default to process.env values (e.g. the IAM
        // role of the Lambda)
        accessKeyId: "",
        secretAccessKey: "",
        sessionToken: ""
    });
 
    // Query for TODOS
    const res = await client.request({
        // The query string - can be manually written, or you can use amplify
        // codegen to create these
        query: `query Todo(id: $id) {
            getTodo(id: $id) {
                id
                title
                description
            }
        }`,
        // Variables to replace (here we are replacing $id with "todoId")
        variables: {
            id: "todoId"
        }
    );
}

Linting queries

If you are using eslint-plugin-graphql, queries need to be tagged so that they can be linted. This module exports gql as a fake tag to do this:

import { gql } from 'appsync-client';
 
const query = gql`query Todo(id: $id) {
        getTodo(id: $id) {
            id
            title
            description
        }
    }`;

Checklist

CD Feature Provided
Typescript
Linting (AirBnB + Prettier)
Unit tests (Jest)
100% test coverage
Github Continuous Deployment

Built by Skyhook

This module is contributed by the team at Skyhook.

Install

npm i appsync-client

DownloadsWeekly Downloads

18

Version

1.10.0

License

MIT

Unpacked Size

116 kB

Total Files

34

Last publish

Collaborators

  • avatar