Trusted Documents
This plugin allows you to define a list of trusted GraphQL documents that can be executed by the gateway (also called Persisted Operations).
For additional information, please refer to Trusted Documents.
Configuration
Examples
This example is using a local file called trusted_documents.json as a store, using the Key->Value map format. The protocol exposed is based on HTTP POST, using the documentId parameter from the request body.
YAML
type: "trusted_documents"
enabled: true
config:
protocols:
- type: "document_id"
field_name: "documentId"
store:
source: "file"
path: "trusted_documents.json"
format: "json_key_value"JSON
{
"type": "trusted_documents",
"enabled": true,
"config": {
"protocols": [
{
"type": "document_id",
"field_name": "documentId"
}
],
"store": {
"source": "file",
"path": "trusted_documents.json",
"format": "json_key_value"
}
}
}Reference
allow_untrustedBy default, this plugin does not allow untrusted operations to be executed. This is a security measure to prevent accidental exposure of operations that are not persisted.
protocolsA list of protocols to be exposed by this plugin. Each protocol defines how to obtain the document ID from the incoming request. You can specify multiple kinds of protocols, if needed.
apollo_manifest_extensions
This protocol is based on Apollo's Persisted Query Extensions. The GraphQL operation key is sent over POST and contains extensions field with the GraphQL document hash.
Example: POST /graphql {"extensions": {"persistedQuery": {"version": 1, "sha256Hash": "123"}}
typeapollo_manifest_extensionsdocument_id
This protocol is based on a POST request with a JSON body containing a field with the document ID. By default, the field name is documentId.
Example: POST /graphql {"documentId": "123", "variables": {"code": "AF"}, "operationName": "test"}
field_name"documentId"The name of the JSON field containing the document ID in the incoming request.
typedocument_idhttp_get
This protocol is based on a HTTP GET request. You can customize where to fetch each one of the parameters from. Each request parameter can be obtained from a different source: query, path, or header. By defualt, all parameters are obtained from the query string.
Unlike other protocols, this protocol does not support sending GraphQL mutations.
Example: GET /graphql?documentId=123&variables=%7B%22code%22%3A%22AF%22%7D&operationName=test
document_id_from{
"source": "search_query",
"name": "documentId"
}Instructions for fetching the document ID parameter from the incoming HTTP request.
search_query
Instructs the plugin to extract this parameter from the query string of the HTTP request.
nameThe name of the HTTP query parameter.
sourcesearch_querypath
Instructs the plugin to extract this parameter from the path of the HTTP request.
positionThe numeric value specific the location of the argument (starting from 0).
sourcepathheader
Instructs the plugin to extract this parameter from a header in the HTTP request.
nameThe name of the HTTP header.
sourceheaderoperation_name_from{
"source": "search_query",
"name": "operationName"
}Instructions for fetching the operationName parameter from the incoming HTTP request.
search_query
Instructs the plugin to extract this parameter from the query string of the HTTP request.
nameThe name of the HTTP query parameter.
sourcesearch_querypath
Instructs the plugin to extract this parameter from the path of the HTTP request.
positionThe numeric value specific the location of the argument (starting from 0).
sourcepathheader
Instructs the plugin to extract this parameter from a header in the HTTP request.
nameThe name of the HTTP header.
sourceheadertypehttp_getvariables_from{
"source": "search_query",
"name": "variables"
}Instructions for fetching the variables parameter from the incoming HTTP request. GraphQL variables must be passed as a JSON-encoded string.
search_query
Instructs the plugin to extract this parameter from the query string of the HTTP request.
nameThe name of the HTTP query parameter.
sourcesearch_querypath
Instructs the plugin to extract this parameter from the path of the HTTP request.
positionThe numeric value specific the location of the argument (starting from 0).
sourcepathheader
Instructs the plugin to extract this parameter from a header in the HTTP request.
nameThe name of the HTTP header.
sourceheaderstoreThe store defines the source of trusted documents. The store contents is a list of hashes and GraphQL documents that are allowed to be executed.
file
File-based store configuration. The path specified is relative to the location of the root configuration file. The file contents are loaded into memory on startup. The file is not reloaded automatically. The file format is specified by the format field, based on the structure of your file.
formatThe format and the expected structure of the loaded store file.
apollo_persisted_query_manifestJSON file formated based on Apollo Persisted Query Manifest.
json_key_valueA simple JSON map of key-value pairs.
Example: {"key1": "query { __typename }"}
pathA path to a local file on the file-system. Relative to the location of the root configuration file.
sourcefile