{"id":17172235,"url":"https://github.com/lucasconstantino/graphql-apq","last_synced_at":"2025-08-13T19:21:24.328Z","repository":{"id":57253331,"uuid":"137710181","full_name":"lucasconstantino/graphql-apq","owner":"lucasconstantino","description":":dart: Automatic persisted queries (APQ) for any GraphQL server.","archived":false,"fork":false,"pushed_at":"2020-04-29T21:58:44.000Z","size":238,"stargazers_count":43,"open_issues_count":3,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-22T00:35:24.835Z","etag":null,"topics":["apollo","apollo-server","express","graphql","persisted-queries"],"latest_commit_sha":null,"homepage":"https://github.com/lucasconstantino/graphql-apq","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/lucasconstantino.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-06-18T04:35:07.000Z","updated_at":"2021-01-30T02:44:12.000Z","dependencies_parsed_at":"2022-08-31T22:11:56.945Z","dependency_job_id":null,"html_url":"https://github.com/lucasconstantino/graphql-apq","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/lucasconstantino%2Fgraphql-apq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Fgraphql-apq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Fgraphql-apq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Fgraphql-apq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasconstantino","download_url":"https://codeload.github.com/lucasconstantino/graphql-apq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248743702,"owners_count":21154722,"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":["apollo","apollo-server","express","graphql","persisted-queries"],"created_at":"2024-10-14T23:36:28.850Z","updated_at":"2025-04-13T16:30:56.521Z","avatar_url":"https://github.com/lucasconstantino.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL APQ\n\n[Automatic persisted queries](https://www.apollographql.com/docs/apollo-server/features/apq) made easy.\n\n[![build status](https://img.shields.io/travis/lucasconstantino/graphql-apq/master.svg?style=flat-square)](https://travis-ci.org/lucasconstantino/graphql-apq)\n[![coverage](https://img.shields.io/codecov/c/github/lucasconstantino/graphql-apq.svg?style=flat-square)](https://codecov.io/github/lucasconstantino/graphql-apq)\n[![npm version](https://img.shields.io/npm/v/graphql-apq.svg?style=flat-square)](https://www.npmjs.com/package/graphql-apq)\n[![sponsored by Taller](https://raw.githubusercontent.com/TallerWebSolutions/tallerwebsolutions.github.io/master/sponsored-by-taller.png)](https://taller.net.br/en/)\n\n---\n\nThis library consists of a server-side implementation of the [persisted queries protocol](https://github.com/apollographql/apollo-link-persisted-queries#protocol) as presented by the [Apollo Engine](https://www.apollographql.com/engine) team.\n\nApollo Engine is a paid GraphQL gateway with many wonderful tools, and this project brings to the open-source world one of those tools.\n\nPersisted queries was [first brought up](https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5) by the Apollo team, but relied mostly on complicated building process to achieve the full benefit proposed. Automatic persisted queries is a concept built on top of that idea, which allows for persisted queries to be registered in run-time.\n\n### How it works\n\n1.  When the client makes a query, it will optimistically send a short (64-byte) cryptographic hash instead of the full query text.\n1.  If the backend recognizes the hash, it will retrieve the full text of the query and execute it.\n1.  If the backend doesn't recogize the hash, it will ask the client to send the hash and the query text to it can store them mapped together for future lookups. During this request, the backend will also fulfill the data request.\n\nThis library is a server implementation for use with any GraphQL server.\n\nYou can use any client-side implementation, as long as it follows the same protocol, but we strongly recommend using the [apollo-link-persisted-queries](https://github.com/apollographql/apollo-link-persisted-queries) project.\n\n## Installation\n\n```\nnpm install graphql-apq --save\n```\n\n## Usage\n\nThis project currently provides a core system for handling persisted queries and an `express` middleware to integrate it to a GraphQL server of choice. It will eventually also provide an `extension` to the Apollo Server project, as soon as [extensions are implemented](https://github.com/apollographql/apollo-server/pull/1105) in that project.\n\n### Middleware\n\n```js\nimport persistedQueries from 'graphql-apq/lib/express'\nimport express from 'express'\nimport bodyParser from 'body-parser'\nimport { graphqlExpress } from 'apollo-server-express'\n\nconst schema = // ... define or import your schema here!\nconst PORT = 3000;\n\nconst app = express();\n\napp\n  .use('/graphql', bodyParser.json(), persistedQueries(), graphqlExpress({ schema }))\n  .listen(PORT)\n```\n\n#### Options\n\nYou can alter some of APQ's default behavior by providing an object of\noptions to the middleware initialization as follows:\n\n##### `cache`\n\nA cache object implementing at least the following interface:\n\n```ts\ninterface CacheInterface {\n  get: (key: string) =\u003e string | null | Promise\u003cstring | null\u003e\n  set: (key: string, value: string) =\u003e void | Promise\u003cvoid\u003e\n  has: (key: string) =\u003e boolean | Promise\u003cboolean\u003e\n}\n```\n\nDefaults to an instance of\n[`memory-cache`](https://github.com/ptarjan/node-cache). Can be modified to\nprovide a more specialized caching system, such as [`node-redis`](https://github.com/NodeRedis/node-redis).\n\n##### `resolveHash`\n\nA reducer from an operation to the hash to use. Defaults to retrieving the\nhash from `operation.extensions.persistedQuery.sha256Hash`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Fgraphql-apq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasconstantino%2Fgraphql-apq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Fgraphql-apq/lists"}