Skip to content

Support for GraphQL persisted queries #7178

@Mosnar

Description

@Mosnar

Description

The concept of persisted queries in GraphQL is essentially that you keep track of your queries in an allow-list with queries mapped to IDs. When executing the query, instead of passing the entire thing, you just pass a queryId. The GraphQL server is then responsible for looking up that query and ensuring it's allowed. Generally, the process of generating the allow list is automated using a frontend build tool to extract queries and generate the allow-list for you, replacing queries with their IDs in your compiled code.

The feature already exists on the webonyx/graphql-php server via the persistentQueryLoader config; however, it would need to be implemented in Craft's implementation.

Benefits

  • Makes it easier to utilize GraphQL as an API in production since you don't need to worry about permissions leaking data
  • Smaller client requests since the payload only needs to carry the query ID
  • Smaller production assets since your queries would be replaced with IDs
  • Improves cachability of http requests since not all full-length queries can fit into GET request parameters to be cached on CDNs

Related Reading

Relay Persisted Queries Reference: https://relay.dev/docs/en/persisted-queries.html
Apollo Server Reference: https://www.apollographql.com/docs/apollo-server/performance/apq/
Example Webpack Loader: https://github.com/leoasis/graphql-persisted-document-loader

Metadata

Metadata

Labels

enhancementimprovements to existing featuresgraphql ⚙️features related to the GraphQL API

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions