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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3

File details

Details for the file django-graphql-persist-0.0.1.dev1.tar.gz.

File metadata

File hashes

Hashes for django-graphql-persist-0.0.1.dev1.tar.gz
Algorithm Hash digest
SHA256 5c9ea0bcedf843828befe49d55218e5c656441f00ec02f5837711a713dab9203
MD5 6d086b5e75e6fd7318bb96f8c6f4f4e3
BLAKE2b-256 442c38318d6e4ee3794594c7e9a44c23bb3c4534b82bfe4f9cfb3ff1abe31314

See more details on using hashes here.

File details

Details for the file django_graphql_persist-0.0.1.dev1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_graphql_persist-0.0.1.dev1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b3bd8aded544eb92cb352e5d60f5eb440c0a0ace74823856f8e6e19cae08d33
MD5 002d79c9128d9fd2d55f4c569bc495ad
BLAKE2b-256 2c02ed28c0d09817e444916b200a4eef7fa30c3611229171ec211445085b39d0

See more details on using hashes here.

Supported by

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