@ttoss/aws-appsync-nodejs
v1.8.19
Published
This package implements a AWS AppSync client for Node.js. We've followed the [AWS Amplify](https://docs.amplify.aws/lib/graphqlapi/graphql-from-nodejs/q/platform/js/) example to create this package.
Downloads
137
Keywords
Readme
@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).
- If you don't provide
apiKey
orcredentials
, 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',
});
- 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',
});
- 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,
},
});