{"id":13514176,"url":"https://github.com/hasura/graphql-serverless","last_synced_at":"2025-06-26T17:34:14.314Z","repository":{"id":87599100,"uuid":"156357325","full_name":"hasura/graphql-serverless","owner":"hasura","description":"Example boilerplates for GraphQL backends hosted on serverless platforms","archived":false,"fork":false,"pushed_at":"2019-01-02T12:10:03.000Z","size":630,"stargazers_count":71,"open_issues_count":5,"forks_count":9,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-23T16:33:12.856Z","etag":null,"topics":["graphql","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","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/hasura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-11-06T09:17:37.000Z","updated_at":"2024-04-01T22:55:41.000Z","dependencies_parsed_at":"2023-07-09T02:18:57.861Z","dependency_job_id":null,"html_url":"https://github.com/hasura/graphql-serverless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hasura/graphql-serverless","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasura%2Fgraphql-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasura%2Fgraphql-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasura%2Fgraphql-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasura%2Fgraphql-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hasura","download_url":"https://codeload.github.com/hasura/graphql-serverless/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasura%2Fgraphql-serverless/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260328652,"owners_count":22992749,"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":["graphql","serverless"],"created_at":"2024-08-01T05:00:48.736Z","updated_at":"2025-06-17T09:32:08.761Z","avatar_url":"https://github.com/hasura.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# GraphQL Serverless\r\n\r\nThis repository contains a set of GraphQL backend boilerplates. These are intended to be useful \r\nreferences for setting up a dead-simple GraphQL resolver that can be deployed on a serverless platform\r\nand interact with a database (Postgres).\r\n\r\nEach boilerplate comprises of:\r\n1. A basic hello world setup\r\n```\r\nquery {\r\n  hello\r\n}\r\n```\r\n\r\n2. Query resolvers that fetch from the database\r\n```\r\nquery {\r\n  user {\r\n    id\r\n    name\r\n    balance\r\n  }\r\n}\r\n```\r\n\r\n3. A Mutation resolver that runs a transaction against the database\r\n```\r\nmutation {\r\n  transferMoney (userFrom, userTo, amount) {\r\n    result\r\n  }\r\n}\r\n```\r\n\r\nThis repository is organised by the serverless platform and runtime which then breaks down into the GraphQL framework + ORM that is being used. For example, [aws-nodejs/apollo-sequelize](aws-nodejs/apollo-sequelize) is a boilerplate for running a GraphQL API on AWS Lambda with Nodejs using the apollo-server framework and the sequelize ORM.\r\n\r\n\r\n## Getting Started\r\n\r\nGet started with the following languages and serverless platforms:\r\n\r\n- [aws-nodejs/apollo-sequelize](aws-nodejs/apollo-sequelize)\r\n- [aws-python/graphene-sqlalchemy](aws-python/graphene-sqlalchemy)\r\n- [aws-go/graphqlgo-gorm](aws-go/graphqlgo-gorm)\r\n\r\n\r\n## Optional: Scaling database interactions for serverless\r\n\r\nIn theory, hosting a GraphQL backend on serverless is very useful because serverless gives us a scalable and no-ops platform to deploy \"business logic\" instantly,\r\n\r\nHowever, serverless backends cannot hold state between different requests because they are destroyed and re-created for every single invocation. This means that our GraphQL backend will cause a database connection to be created and destroyed for every invoation and will result in increased latency and be expensive for the database. A database is optimised for handling upto a few 100 long-living connections, and not a few thousand short-living connections.\r\n\r\n#### Connection pooling with pgBouncer\r\n\r\nTo make our GraphQL backend scale at the same rate as serverless invocations, we will use a standalone connection pooler like [pgBouncer](https://pgbouncer.github.io/) to proxy our connections to the database.\r\n\r\n![architecture](_assets/architecture.png)\r\n\r\npgBouncer maintains a persistent connection pool with the database but allows applications to create a large number of connections which it proxies to Postgres. We will deploy pgBouncer on a free EC2 instance. We can use the CloudFormation template present in this repo: [cloudformation.json](cloudformation/cloudformation.json) to deploy a pgBouncer EC2 instance in few clicks.\r\n\r\n#### Results\r\n\r\nUsing pgBouncer, here are typical results for corresponding rate of Lambda invocations. The tests were conducted with the `addUser` mutation using [jmeter](https://jmeter.apache.org/).\r\n\r\n|  Error Rate -\u003e | Without pgBouncer | With pgBouncer|\r\n| -------------- | ----------------- | ------------- |\r\n| 100 req/s      | 86%               | 0%            |\r\n| 1000 req/s     | 92%               | 4%            |\r\n| 10000 req/s    | NA                | 3%            |\r\n\r\nNote: The table above indicates the success (2xx) or failure (non-2xx) of requests when instantiated at X req/s and not the throughput of those requests.\r\n\r\n## Using with Hasura GraphQL Engine\r\n\r\nYou can use these boilerplates to create any kind of GraphQL API. Resolvers that interact with other microservices or  with a database, we started putting together this repository you may wish to merge your schema with [Hasura GraphQL Engine](https://hasura.io) to augment your schema with high-performance CRUD and realtime GraphQL APIs.\r\n\r\nFollow this guide to merge your schema with Hasura: [using-with-hasura.md](using-with-hasura.md)\r\n\r\n## CONTRIBUTING\r\n\r\nWe strongly encourage contributions of boilerplates in other languages, frameworks/ORM or serverless platforms. Please follow [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on contributing.\r\n\r\nCheck out some of the [open issues](https://github.com/hasura/graphql-serverless/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) which require community help.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasura%2Fgraphql-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasura%2Fgraphql-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasura%2Fgraphql-serverless/lists"}