{"id":19201035,"url":"https://github.com/dabit3/lambda-graphql-resolver-examples","last_synced_at":"2025-11-17T15:20:44.732Z","repository":{"id":41493117,"uuid":"191207914","full_name":"dabit3/lambda-graphql-resolver-examples","owner":"dabit3","description":"Examples of using AWS Lambda Functions as GraphQL Resolvers with the Amplify CLI","archived":false,"fork":false,"pushed_at":"2021-06-16T00:59:52.000Z","size":1123,"stargazers_count":33,"open_issues_count":14,"forks_count":25,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-09T09:58:59.192Z","etag":null,"topics":["aws-amplify","aws-appsync","dynamodb","graphql","react","serverless"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabit3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-10T16:46:35.000Z","updated_at":"2023-02-23T09:43:58.000Z","dependencies_parsed_at":"2022-09-03T19:00:48.842Z","dependency_job_id":null,"html_url":"https://github.com/dabit3/lambda-graphql-resolver-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dabit3/lambda-graphql-resolver-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Flambda-graphql-resolver-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Flambda-graphql-resolver-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Flambda-graphql-resolver-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Flambda-graphql-resolver-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabit3","download_url":"https://codeload.github.com/dabit3/lambda-graphql-resolver-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabit3%2Flambda-graphql-resolver-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284906844,"owners_count":27082737,"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","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aws-amplify","aws-appsync","dynamodb","graphql","react","serverless"],"created_at":"2024-11-09T12:35:59.067Z","updated_at":"2025-11-17T15:20:44.715Z","avatar_url":"https://github.com/dabit3.png","language":"JavaScript","readme":"# AWS AppSync - Lambda GraphQL Resolver Examples\n\n## Resources in this project\n\n```sh\n~ amplify status\n\nCurrent Environment: local\n\n| Category | Resource name    | Operation | Provider plugin   |\n| -------- | ---------------- | --------- | ----------------- |\n| Storage  | currencytable    | No Change | awscloudformation |\n| Function | currencyfunction | No Change | awscloudformation |\n| Api      | gqllambdacrypto  | No Change | awscloudformation |\n```\n\n### API - AWS AppSync (GraphQL)\n\n#### Schema\n\nThis schema has 1 main type (`Coin`) as well as `Query` and a `Mutation` operation to interact with the type. The resolver for these operations is the Lambda function (`currencyfunction`).\n\n```graphql\ntype Coin {\n  id: String!\n  name: String!\n  symbol: String!\n  price_usd: String!\n}\n\ntype Query {\n  getCoins(limit: Int start: Int): [Coin] @function(name: \"currencyfunction-${env}\")\n}\n\ntype Mutation {\n  createCoin(name: String! symbol: String! price_usd: String!): Coin @function(name: \"currencyfunction-${env}\")\n}\n```\n\n### Function - AWS Lambda\n\nThe Function has two main features: \n\n1. Fetch from a REST API and return the results.\n\n2. Interact with a DynamoDB Table (putItem and Scan)\n\n#### index.js\n\n```javascript\n// index.js\nconst axios = require('axios')\n\nconst getCoins = require('./getCoins')\nconst createCoin = require('./createCoin')\n\nexports.handler = function (event, _, callback) {\n  // uncomment to invoke DynamoDB with putItem or Scan\n  // if (event.typeName === 'Mutation') {\n  //   createCoin(event, callback)\n  // }\n  // if (event.typeName === 'Query') {\n  //   getCoins(callback)\n  // }\n  \n  // call another API and return the response (query only)\n  let apiUrl = `https://api.coinlore.com/api/tickers/?start=1\u0026limit=10`\n\n  if (event.arguments) { \n    const { start = 0, limit = 10 } = event.arguments\n    apiUrl = `https://api.coinlore.com/api/tickers/?start=${start}\u0026limit=${limit}`\n  }\n  \n  axios.get(apiUrl)\n    .then(response =\u003e callback(null, response.data.data))\n    .catch(err =\u003e callback(err))\n}\n```\n\n#### getCoins.js\n\n```javascript\n// getCoins.js\nconst AWS = require('aws-sdk')\nconst region = process.env.REGION\nconst storageCurrencytableName = process.env.STORAGE_CURRENCYTABLE_NAME\nconst docClient = new AWS.DynamoDB.DocumentClient({region})\n\nconst params = {\n  TableName: storageCurrencytableName\n}\n\nfunction getCoins(callback) {\n  docClient.scan(params, function(err, data) {\n    if (err) {\n      callback(err)\n    } else {\n      callback(null, data.Items)\n    }\n  });\n}\n\nmodule.exports = getCoins\n```\n\n#### createCoin.js\n\n```javascript\n// createCoin.js\nconst AWS = require('aws-sdk')\nconst uuid = require('uuid/v4')\nconst region = process.env.REGION\nconst ddb_table_name = process.env.STORAGE_CURRENCYTABLE_NAME\nconst docClient = new AWS.DynamoDB.DocumentClient({region})\n\nfunction write(params, event, callback){\n  docClient.put(params, function(err, data) {\n    if (err) {\n      callback(err)\n    } else {\n      callback(null, event.arguments)\n    }\n  })\n}\n\nfunction createCoin(event, callback) {\n  const args = { ...event.arguments, id: uuid() }\n  var params = {\n    TableName: ddb_table_name,\n    Item: args\n  };\n  \n  if (Object.keys(event.arguments).length \u003e 0) {\n    write(params, event, callback)\n  } \n}\n\nmodule.exports = createCoin\n```\n\n### Storage - Amazon DynamoDB\n\nThis table has the following properties:\n\n- id\n- name\n- symbol\n- price_usd\n\n## Deploy this app\n\n__To deploy this project, you can do one of the following:__\n\n### 1. Use the AWS Amplify 1-click deploy button\n\n[![amplifybutton](https://oneclick.amplifyapp.com/button.svg)](https://console.aws.amazon.com/amplify/home#/deploy?repo=https://github.com/dabit3/lambda-graphql-resolver-examples)\n\n### 2. Deploy from your local machine\n\n1. Clone the repo\n\n```sh\ngit clone https://github.com/dabit3/lambda-graphql-resolver-examples.git\n\ncd lambda-graphql-resolver-examples\n```\n\n2. Install dependencies\n\n```sh\nnpm install\n```\n\n3. Initialize new Amplify repository\n\n```sh\namplify init\n```\n\n4. Deploy\n\n```sh\namplify push\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabit3%2Flambda-graphql-resolver-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabit3%2Flambda-graphql-resolver-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabit3%2Flambda-graphql-resolver-examples/lists"}