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

The timeout, in seconds, to use for the cache (infinite by default).
Default: None

KEY_PREFIX

A string that will be automatically prepended to all cache keys used for persisted queries.
Default: 'persist'

CACHE_KEY_HANDLER

...
Default: lambda document_id, request: document_id

PERSISTED_RESPONSE_HANDLER

...
Default: None

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.dev0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

django_graphql_persist-0.0.1.dev0-py2.py3-none-any.whl (5.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