Package: django-graphql-persist
Persisted queriesforDjango GraphQLDependenciesDjango ≥ 1.11Python ≥ 3.4InstallationInstall last stable version from Pypi.pipinstalldjango-graphql-persistInclude thePersistMiddlewaremiddleware in yourMIDDLEWAREsettings:MIDDLEWARE=[...'graphql_persist.middleware.PersistMiddleware',...]LoadersDjango-graphql-persistsearches for documents directories in a number of places, depending on yourDEFAULT_LOADER_CLASSESvariable.By default,Django-graphql-persistuses these document loaders:AppDirectoriesLoaderLoads documents from Django apps on the filesystem. For each app inINSTALLED_APPS, the loader looks for adocuments/subdirectory defined byAPP_DOCUMENT_DIRvariable.FilesystemLoaderLoads documents from the filesystem, according toDOCUMENTS_DIRSvariable.URLLoaderLoads documents from urls, according toDOCUMENTS_DIRS.GRAPHQL_PERSIST={'DOCUMENTS_DIRS':['/app/documents',# FilesystemLoader'https:// ... /documents',# URLLoader],}Cached LoaderBy default, the document system reads your documents every time they’re rendered.Configure theCachedEngineengine for caching documents.GRAPHQL_PERSIST={'DEFAULT_LOADER_ENGINE_CLASS':[graphql_persist.loaders.CachedEngine',],}Persisted Query definitionYou can split schemas into separate files…documents/fragments.graphqlfragment userFields on UserType {
  id
  email
}and define Pythonic imports prefixed with#.documents/GetViewer.graphql# from fragments import userFields

{
  viewer {
    ...userFields
  }
}Persisted Query byid{"id":"GetViewer","variables":{}}Multiple Operationsdocuments/users.graphql# from fragments import userFields

query GetViewer {
  viewer {
    ...userFields
  }
}

query GetUsers($last: Int!) {
  users(last: $last) {
    ...userFields
  }
}Persisted Query byidandoperationName{"id":"users","operationName":"GetUsers","variables":{"last":2}}✋ VersioningThe versioning scheme is defined by theDEFAULT_VERSIONING_CLASSsetting variable.GRAPHQL_PERSIST={'DEFAULT_VERSIONING_CLASS':'graphql_persist.versioning.AcceptHeaderVersioning'}This is the fulllist of versioning classes.DEFAULT_VERSIONING_CLASSExampleAcceptHeaderVersioningapplication/json; version=v1VendorTreeVersioningapplication/vnd.example.v1+jsonQueryParameterVersioning?version=v1HostNameVersioningv1.example.comConfigure the versioning scheme and storage the GraphQL documents according to the version.👇ExamplePOST /graphql HTTP/1.1
Accept: application/json; version=v1.full

{
  "id": "GetViewer",
  "variables": {}
}documents/
|
├── v1/
│   ├── full/
│   |     └── GetViewer.graphql 👈
│   └── basic/
|   |     └── GetViewer.graphql
|   └── fragments/
|         └── users.graphql
└── v2/
    └── full/
    └── basic/👉documents/v1/full/GetViewer.graphql# from ..fragments.users import userFields

{
  viewer {
    ...userFields
  }
}SettingsHere’s alist of settingsavailable inDjango-graphql-persistand their default values.DOCUMENTS_DIRSList of directories or urls searched for GraphQL SDL definitions
Default: ()CACHE_NAMECache key name `CACHES[name]` to cache the queries results
Default: 'default'QUERY_KEY_HANDLERA custom function `f(query_id, request)` to generate the persisted query keys
Default: 'graphql_persist.query.query_key_handler'DEFAULT_VERSIONING_CLASSA versioning class to determine the `request.version` attribute
Default: NoneDEFAULT_LOADER_ENGINE_CLASSClass that takes a list of template loaders and attempts to load templates from them in order
Default: 'graphql_persist.loaders.Engine'
Note: Set variable to 'graphql_persist.loaders.CachedEngine' for caching documentsDEFAULT_LOADER_CLASSESA list of loader classes to import documents from a particular source
Default: (
    'graphql_persist.loaders.AppDirectoriesLoader',
    'graphql_persist.loaders.FilesystemLoader',
    'graphql_persist.loaders.URLLoader',
)APP_DOCUMENT_DIRSubdirectory of installed applications for searches documents
Default: 'documents'DOCUMENTS_EXTGraphQL document file extension
Default: '.graphql'DEFAULT_RENDERER_CLASSESA list of renderer classes that may be used when returning a persisted query response
Default: ()