Skip to main content

Persisted queries for Django GraphQL

Project description

Pypi Wheel Build Status Codecov Code Climate

Persisted queries for Django GraphQL

Dependencies

  • Django ≥ 1.11

  • Python ≥ 3.4

Installation

Install last stable version from Pypi.

pip install django-graphql-persist

Include the PersistMiddleware middleware in your MIDDLEWARE settings:

MIDDLEWARE = [
    ...
    'graphql_persist.middleware.PersistMiddleware',
    ...
]

Configure the list of directories searched for GraphQL SDL definitions.

GRAPHQL_PERSIST = {
    'DOCUMENTS_DIRS': [
        '/app/documents',
    ],
}

Schema definition

/app/documents/schema.graphql

query GetViewer {
  viewer {
    ...userFields
  }
}

query GetUsers {
  users {
    ...userFields
  }
}

fragment userFields on UserType {
  id
  email
}

Query by “id”

{
  "id": "schema",
  "operationName": "GetViewer",
  "variables": {}
}

Operations definition

The server needs to do less processing to parse the query and verify the parameters.

/app/documents/GetViewer.graphql

query GetViewer {
  viewer {
    ...userFields
  }
}

fragment userFields on UserType {
  id
  email
}

Query by “operationName”

{
  "operationName": "GetViewer",
  "variables": {}
}

Settings

Here’s a list of settings available in Django-graphql-persist and their default values.

DOCUMENTS_DIRS

List of directories searched for GraphQL SDL definitions
Default: None

CACHE_NAME

This selects the cache to use.
Default: 'default'

CACHE_TIMEOUT_HANDLER

A custom function to generate the timeout, in seconds, to use for the cache
Default: lambda query_key: 0 if settings.DEBUG else None

QUERY_KEY_HANDLER

A custom function to generate the persisted query key
Default: lambda query_id, request: query_id

DEFAULT_RENDERER_CLASSES

A list or tuple of renderer classes that may be used when returning a persisted query response
Default: ()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-graphql-persist-0.0.1.dev1.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

django_graphql_persist-0.0.1.dev1-py2.py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page