{"id":20613943,"url":"https://github.com/dgraph-io/dgraph-lambda","last_synced_at":"2025-04-04T18:04:39.793Z","repository":{"id":45230929,"uuid":"296678196","full_name":"dgraph-io/dgraph-lambda","owner":"dgraph-io","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-23T10:42:40.000Z","size":477,"stargazers_count":41,"open_issues_count":0,"forks_count":14,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-03-28T17:09:50.585Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"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/dgraph-io.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-18T16:45:56.000Z","updated_at":"2025-03-18T13:15:10.000Z","dependencies_parsed_at":"2024-04-12T14:42:40.827Z","dependency_job_id":"247db6d0-0b57-4821-93be-eaacb39d0774","html_url":"https://github.com/dgraph-io/dgraph-lambda","commit_stats":{"total_commits":68,"total_committers":12,"mean_commits":5.666666666666667,"dds":0.4558823529411765,"last_synced_commit":"e049d5c61227fd91629a17130b6090cc75b2ffc2"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fdgraph-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fdgraph-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fdgraph-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgraph-io%2Fdgraph-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgraph-io","download_url":"https://codeload.github.com/dgraph-io/dgraph-lambda/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226213,"owners_count":20904465,"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-16T11:11:28.429Z","updated_at":"2025-04-04T18:04:39.774Z","avatar_url":"https://github.com/dgraph-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dgraph Lambda\n\nDgraph Lambda is a serverless platform for running JS on Slash GraphQL (or Dgraph).\n\n## Running a script\n\nA script looks something like this. There are two ways to add a resolver\n* `addGraphQLResolver` which recieves `{ parent, args }` and returns a single value\n* `addMultiParentGraphQLResolver` which received `{ parents, args }` and should return an array of results, each result matching to one parent. This method will have much better performance if you are able to club multiple requests together\n\nIf the query is a root query/mutation, parents will be set to `[null]`.\n\n```javascript\nconst fullName = ({ parent: { firstName, lastName } }) =\u003e `${firstName} ${lastName}`\n\nasync function todoTitles({ graphql }) {\n  const results = await graphql('{ queryTodo { title } }')\n  return results.data.queryTodo.map(t =\u003e t.title)\n}\n\nself.addGraphQLResolvers({\n  \"User.fullName\": fullName,\n  \"Query.todoTitles\": todoTitles,\n})\n\nasync function reallyComplexDql({parents, dql}) {\n  const ids = parents.map(p =\u003e p.id);\n  const someComplexResults = await dql(`really-complex-query-here with ${ids}`);\n  return parents.map(parent =\u003e someComplexResults[parent.id])\n}\n\nself.addMultiParentGraphQLResolvers({\n  \"User.reallyComplexProperty\": reallyComplexDql\n})\n```\n\n## Running Locally\n\nCreate a \"local-lambda\" docker image\n``` \ndocker build -t local-lambda .\n```\n###  option 1 - run the lambda server alone with\n```\ndocker run -d -p 8686:8686 local-lambda\n```\nYou can perform a basic test using curl:\n\n```bash\ncurl localhost:8686/graphql-worker -H \"Content-Type: application/json\" -d '{\"resolver\":\"User.fullName\",\"parents\":[{\"firstName\":\"Dgraph\",\"lastName\":\"Labs\"}]}'\n```\n\n\n### option 2 - use one of the scripts in dgraph/contrib/local-test\n\n- change the lambda image used in the script to use local-lambda for your tests\n- check the script you want to load. To run the lambda jest, load the script provided in this repo.\n\nFor testing, update exosystem.config.js\n\n- add node_args: [\"--inspect\"], to enable debugging.\n- set instances to 1, to be sure that the port 9230 will be on the only instance your are testing.\n\nin VS code, attach to the docker container, and then launch the debug confugration \"Attach to Process\"\n\n\n### Tests\nrun \n```\ndocker-compose up\n``` \nto get an cluster with Dgraph zero, alpha and lambda server\n\nrun \n\n```\nexport DGRAPH_URL=http://localhost:8080\n\nexport INTEGRATION_TEST=true \n\nnpm test\n```\nto execute the tests.\n\n\n\n## Environment\n\nWe are trying to make the environment match the environment you'd get from ServiceWorker.\n\n* [x] fetch\n* [x] graphql / dql\n* [x] base64\n* [x] URL\n* [ ] crypto - should test this\n\n## Adding libraries\n\nIf you would like to add libraries, then use webpack --target=webworker to compile your script. We'll fill out these instructions later.\n\n### Working with Typescript\n\nYou can import `@slash-graphql/lambda-types` to get types for `addGraphQLResolver` and `addGraphQLMultiParentResolver`.\n\n## Security\n\nCurrently, this uses node context to try and make sure that users aren't up to any fishy business. However, contexts aren't true security, and we should eventually switch to isolates. In the meanwhile, we will basically have kube kill this if it takes a lot of CPU for say 5 secs\n\n## Publishing\n\nCurrently, the publishing of this isn't automated. In order to publish:\n* Publish the types in slash-graphql-lambda-types if needed with (npm version minor; npm publish)\n* The docker-image auto publishes, but pushing a tag will create a tagged version that is more stable\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraph-io%2Fdgraph-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgraph-io%2Fdgraph-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgraph-io%2Fdgraph-lambda/lists"}