{"id":14070653,"url":"https://github.com/ttoss/aws-appsync-backend","last_synced_at":"2025-10-16T04:31:41.676Z","repository":{"id":41782813,"uuid":"265792919","full_name":"ttoss/aws-appsync-backend","owner":"ttoss","description":"AWS AppSync client for backend","archived":false,"fork":false,"pushed_at":"2022-11-10T07:46:50.000Z","size":273,"stargazers_count":7,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-04T12:41:18.684Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ttoss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-21T08:16:27.000Z","updated_at":"2022-12-11T01:07:48.000Z","dependencies_parsed_at":"2023-01-22T00:16:30.866Z","dependency_job_id":null,"html_url":"https://github.com/ttoss/aws-appsync-backend","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttoss%2Faws-appsync-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttoss%2Faws-appsync-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttoss%2Faws-appsync-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttoss%2Faws-appsync-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttoss","download_url":"https://codeload.github.com/ttoss/aws-appsync-backend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236677573,"owners_count":19187477,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:08:00.844Z","updated_at":"2025-10-16T04:31:36.366Z","avatar_url":"https://github.com/ttoss.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# AWS AppSync Backend\n\n[AWS AppSync](https://aws.amazon.com/appsync/) client for a NodeJS App. This package is a wrap of [this tutorial](https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-node.html).\n\nThis client is a [Apollo JavaScript client](https://github.com/apollographql/apollo-client) plus the authentication method that we need to access AWS AppSync URL (more details about authentication method can be found on the [AWS AppSync JavaScript SDK docs](https://github.com/awslabs/aws-mobile-appsync-sdk-js#using-authorization-and-subscription-links-with-apollo-client-no-offline-support)). Also, this backend client adds fetch polyfills and WebSocket to perform subscriptions.\n\n---\n\n## Installation\n\n#### npm\n\n```shell\nnpm install --save @ttoss/aws-appsync-backend\n```\n\n#### yarn\n\n```shell\nyarn add @ttoss/aws-appsync-backend\n```\n\n---\n\n## Getting Started\n\n**You must have AWS CLI installed and have the permissions to create AWS AppSync resources.**\n\n_\\*note: in this section, we'll use `AWSAppSyncBackendCoolChat` as the stack name, but you may choose any name you want._\n\n### Deploy AWS AppSync API\n\nWe've provided a [simple chat example](example/cloudformation.yml) using a CloudFormation template which creates an AWS AppSync API with few GraphQL operations.\n\nTo deploy the API, run this command:\n\n```shell\n$ aws cloudformation deploy --stack-name AWSAppSyncBackendCoolChat --template-file ./path_to_template/cloudformation.yml\n```\n\nAlso, you may clone this project and run the command:\n\n```shell\n$ npm run example:deploy\n```\n\n#### Get the URL and API key\n\nAfter deployed, you can get the URL and API key accessing the AWS AppSync or the CloudFormation console and check the stack outputs.\n\nAlso, you can get them running the command:\n\n```shell\n$ aws cloudformation describe-stacks --stack-name AWSAppSyncBackendCoolChat --query 'Stacks[0].Outputs'\n```\n\nWhich will return something like this:\n\n```yml\n- OutputKey: ApiKey\n  OutputValue: da2-rvbbc6xzkXXXXXXX\n- OutputKey: Url\n  OutputValue: https://vnkglexXXXXX.appsync-api.us-east-1.amazonaws.com/graphql\n```\n\n### GraphQL operations\n\n#### Create the client\n\n```ts\nimport { AwsAppSyncBackend, AuthOptions, AUTH_TYPE, gql } from '@ttoss/aws-appsync-backend';\n\nconst url = ... // your URL here\n\nconst auth: AuthOptions = {\n  type: AUTH_TYPE.API_KEY,\n  apiKey: ... // your API key here\n};\n\nconst awsAppSyncBackend = AwsAppSyncBackend({ url, auth });\n```\n\n#### Query\n\n```ts\nawsAppSyncBackend\n  .query({\n    query: gql`\n      query {\n        oldMessages {\n          author\n          dateTime\n          content\n        }\n      }\n    `,\n  })\n  .then(({ data }) =\u003e {\n    console.log(data.oldMessages);\n  })\n  .catch((err) =\u003e {\n    console.error('Occurred an error.');\n    console.log(err);\n  });\n```\n\n#### Mutation\n\n```ts\nconst author = 'Pedro';\nconst content = 'Hello again!';\n\nawsAppSyncBackend\n  .mutate({\n    mutation: gql`\n      mutation sendMessageMutation($author: String!, $content: String!) {\n        sendMessage(author: $author, content: $content) {\n          author\n          dateTime\n          content\n        }\n      }\n    `,\n    variables: { author, content },\n  })\n  .then(({ data }) =\u003e {\n    console.log(data.sendMessage);\n  })\n  .catch((err) =\u003e {\n    console.error('Occurred an error.');\n    console.log(err);\n  });\n```\n\n#### Subscription\n\n```ts\nawsAppSyncBackend\n  .subscribe({\n    query: gql`\n      subscription {\n        sentMessage {\n          author\n          dateTime\n          content\n        }\n      }\n    `,\n  })\n  .subscribe({\n    next: ({ data }) =\u003e console.log(data.sentMessage),\n    error: (err) =\u003e {\n      console.error('Occurred an error.');\n      console.log(err);\n    },\n    complete: () =\u003e console.log('Completed.'),\n  });\n```\n\n#### Using the provided example\n\nIf you want to use the [example](example/example.ts) we've created, you just need to run these commands:\n\n```shell\n$ npm run example:query\n$ npm run example:mutation -- --author Pedro --content \"Hi\"\n$ npm run example:subscription\n```\n\n### Destroy AWS AppSync API\n\nFinally, you may want to destroy the stack created running the command:\n\n```shell\n$ aws cloudformation destroy --stack-name AWSAppSyncBackendCoolChat\n```\n\nIf you're using our example:\n\n```shell\n$ npm run destroy\n```\n\n## Author\n\n- [Pedro Arantes](https://twitter.com/arantespp)\n\n---\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttoss%2Faws-appsync-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttoss%2Faws-appsync-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttoss%2Faws-appsync-backend/lists"}