{"id":21930057,"url":"https://github.com/aheissenberger/serverless-appsync-offline","last_synced_at":"2025-08-20T08:31:37.242Z","repository":{"id":47628221,"uuid":"148390987","full_name":"aheissenberger/serverless-appsync-offline","owner":"aheissenberger","description":"Serverless AWS AppSync Offline Plugin - Allow to run AppSync locally for serverless framework","archived":false,"fork":false,"pushed_at":"2022-05-25T08:43:09.000Z","size":289,"stargazers_count":90,"open_issues_count":10,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-15T14:48:51.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/aheissenberger.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":"2018-09-11T23:05:13.000Z","updated_at":"2023-01-28T01:59:43.000Z","dependencies_parsed_at":"2022-09-06T12:13:03.559Z","dependency_job_id":null,"html_url":"https://github.com/aheissenberger/serverless-appsync-offline","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aheissenberger%2Fserverless-appsync-offline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aheissenberger%2Fserverless-appsync-offline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aheissenberger%2Fserverless-appsync-offline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aheissenberger%2Fserverless-appsync-offline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aheissenberger","download_url":"https://codeload.github.com/aheissenberger/serverless-appsync-offline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230408170,"owners_count":18220974,"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-11-28T23:07:33.192Z","updated_at":"2024-12-19T09:06:32.615Z","avatar_url":"https://github.com/aheissenberger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"serverless-appsync-offline\n=================================\n\n[![npm version](https://badge.fury.io/js/serverless-appsync-offline.svg)](https://badge.fury.io/js/serverless-appsync-offline)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis is a wrapper for the excellent [AppSync Emulator](https://github.com/ConduitVC/aws-utils/tree/appsync/packages/appsync-emulator-serverless).\n\n**Attention**\n\u003e Since the libraries from Conduit `@conduitvc/appsync-emulator-serverless` are no longer maintained this library cannot be maintained too.\n\u003e Please switch to [serverless-appsync-simulator](https://github.com/serverless-appsync/serverless-appsync-simulator) which wraps the offical AWS AppSync [amplify-appsync-simulator](https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-appsync-simulator).\n\n## This Plugin Requires\n* serverless@v1-rc.1\n\n## Features\n* Emulate Appsync with [AppSync Emulator](https://github.com/ConduitVC/aws-utils/tree/appsync/packages/appsync-emulator-serverless) and depends on [Serverless-AppSync-Plugin](https://github.com/sid88in/serverless-appsync-plugin)\n* Connect to any DynamoDB or install DynamoDB Local\n* Start DynamoDB Local with all the parameters supported (e.g port, inMemory, sharedDb)\n* Table Creation for DynamoDB Local\n\nThis plugin is updated by its users, I just do maintenance and ensure that PRs are relevant to the community. In other words, if you [find a bug or want a new feature](https://github.com/aheissenberger/serverless-appsync-offline/issues), please help us by becoming one of the contributors.\n\n## \n\n## Install Plugin\n`npm install --save serverless-appsync-offline`\n\nThen in `serverless.yml` add following entry to the plugins array: `serverless-appsync-offline`\n```yml\nplugins:\n  - serverless-appsync-offline\n```\n\n## Using the Plugin\n\n\n1) Add Appsync Resource definitions to your Serverless configuration, as defined here: https://github.com/sid88in/serverless-appsync-plugin#configuring-the-plugin\n\n\n\n\n## Start appsync-offline\n\n`sls appsync-offline start`\n\nAll CLI options are optional:\n\n```\n--port  \t\t  -p  Port to provide the graphgl api. Default: dynamic\n--dynamoDbPort            -d  Port to access the dynamoDB. Default: dynamic\n--inMemory                -i  DynamoDB; will run in memory, instead of using a database file. When you stop DynamoDB;, none of the data will be saved. Note that you cannot specify both -dbPath and -inMemory at once.\n--dbPath                  -b  The directory where DynamoDB will write its database file. If you do not specify this option, the file will be written to the current directory. Note that you cannot specify both -dbPath and -inMemory at once. For the path, current working directory is \u003cprojectroot\u003e/node_modules/serverless-appsync-offline/dynamob. For example to create \u003cprojectroot\u003e/node_modules/serverless-appsync-offline/dynamob/\u003cmypath\u003e you should specify -d \u003cmypath\u003e/ or --dbPath \u003cmypath\u003e/ with a forwardslash at the end.\n--sharedDb                -h  DynamoDB will use a single database file, instead of using separate files for each credential and region. If you specify -sharedDb, all DynamoDB clients will interact with the same set of tables regardless of their region and credential configuration.\n--delayTransientStatuses  -t  Causes DynamoDB to introduce delays for certain operations. DynamoDB can perform some tasks almost instantaneously, such as create/update/delete operations on tables and indexes; however, the actual DynamoDB service requires more time for these tasks. Setting this parameter helps DynamoDB simulate the behavior of the Amazon DynamoDB web service more closely. (Currently, this parameter introduces delays only for global secondary indexes that are in either CREATING or DELETING status.)\n--optimizeDbBeforeStartup -o  Optimizes the underlying database tables before starting up DynamoDB on your computer. You must also specify -dbPath when you use this parameter.\n```\n\nAll the above options can be added to serverless.yml to set default configuration: e.g.\n\n**Minimum Options:**\n```yml\ncustom:\n  appsync-offline:\n    port: 62222\n    dynamodb:\n      server:\n        port: 8000\n```\n**All Options:**\n```yml\ncustom:\n  appsync-offline:\n    port: 62222\n    dynamodb:\n      client:\n        # if endpoint is provided, no local database server is started and and appsync connects to the endpoint - e.g. serverless-dynamodb-local\n        endpoint: \"http://localhost:8000\"\n        region: localhost\n        accessKeyId: a\n        secretAccessKey: a\n      server:\n        port: 8000\n        dbPath: \"./.dynamodb\"\n        inMemory: false,\n        sharedDb: false,\n        delayTransientStatuses: false,\n        optimizeDbBeforeStartup: false,\n```\n\n**How to Query:**\n```sh\ncurl -X POST \\\n  http://localhost:62222/graphql \\\n  -H 'Content-Type: application/json' \\\n  -H 'x-api-key: APIKEY' \\\n  -d '{\n\t\"query\": \"{ hello { world } }\"\n}'\n```\n\n_**Note**: If you're using `API_KEY` as your authenticationType, then a `x-api-key` header has to be present in the request. The value of the key doesn't really matter._\n\n## Using DynamoDB Local in your code\nYou need to add the following parameters to the AWS NODE SDK dynamodb constructor\n\ne.g. for dynamodb document client sdk\n```\nvar AWS = require('aws-sdk');\n```\n```\nnew AWS.DynamoDB.DocumentClient({\n    region: 'localhost',\n    endpoint: 'http://localhost:8000'\n})\n```\ne.g. for dynamodb document client sdk\n```\nnew AWS.DynamoDB({\n    region: 'localhost',\n    endpoint: 'http://localhost:8000'\n})\n```\n\n### Using with serverless-offline plugin\nWhen using this plugin with serverless-offline, it is difficult to use above syntax since the code should use DynamoDB Local for development, and use DynamoDB Online after provisioning in AWS. Therefore we suggest you to use [serverless-dynamodb-client](https://github.com/99xt/serverless-dynamodb-client) plugin in your code.\n\nThe `serverless appsync-offline start` command can be triggered automatically when using `serverless-offline` plugin.\n\n\nAdd both plugins to your `serverless.yml` file:\n```yaml\nplugins:\n  - serverless-appsync-offline\n  - serverless-offline\n```\n\nMake sure that `serverless-appsync-offline` is above `serverless-offline` so it will be loaded earlier.\n\nNow your local Appsync and the DynamoDB database will be automatically started before running `serverless offline`.\n\n### Debugging\n\n`SLS_DEBUG=* NODE_DEBUG=appsync-* yarn offline`\n\nor\n\n`SLS_DEBUG=* NODE_DEBUG=appsync-* yarn sls appsync-offline start`\n\n\n### Using with serverless-offline and serverless-webpack plugin\nRun `serverless offline start`. In comparison with `serverless offline`, the `start` command will fire an `init` and a `end` lifecycle hook which is needed for serverless-offline and serverless-appsync-offline to switch off both resources.\n\nAdd plugins to your `serverless.yml` file:\n```yaml\nplugins:\n  - serverless-webpack\n  - serverless-appsync-offline\n  - serverless-offline #serverless-offline needs to be last in the list\n\ncustom:\n  appsync-emulator:\n    # when using serverless-webpack it (by default) outputs all the build assets to `\u003cprojectRoot\u003e/.webpack/service`\n    # this will let appsync-offline know where to find those compiled files\n    buildPrefix: .webpack/service\n```\n\n## Notes\n\nThe [AppSync Emulator](https://github.com/ConduitVC/aws-utils/tree/appsync/packages/appsync-emulator-serverless) does not support CloudFormation syntax (e.g. `tableName: { Ref: UsersTable }`) in `dataSources`. \n\n## License\n  [MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faheissenberger%2Fserverless-appsync-offline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faheissenberger%2Fserverless-appsync-offline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faheissenberger%2Fserverless-appsync-offline/lists"}