Skip to main content

Hypothesis strategies for GraphQL schemas and queries

Project description

Build status for master branch Version Python versions Gitter License

Hypothesis strategies for GraphQL schemas, queries and data.

NOTE This package is experimental, some features are not supported yet.


There are two strategies for different use cases.

  1. Schema generation - hypothesis_graphql.strategies.schema()
  2. Query - hypothesis_graphql.strategies.query(schema).

Lets take this schema as an example:

type Book {
  title: String
  author: Author

type Author {
  name: String
  books: [Book]

type Query {
  getBooks: [Book]
  getAuthors: [Author]

Then strategies might be used in this way:

from hypothesis import given
from hypothesis_graphql import strategies as gql_st

SCHEMA = "..."  # the one above

def test_query(query):
    # This query might be generated:
    # query {
    #   getBooks {
    #     title
    #   }
    # }

To restrict the set of fields in generated queries use the fields argument:


@given(query=gql_st.query(SCHEMA, fields=["getAuthors"]))
def test_query(query):
    # Only `getAuthors` will be generated

Project details

Download files

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

Files for hypothesis-graphql, version 0.5.1
Filename, size File type Python version Upload date Hashes
Filename, size hypothesis_graphql-0.5.1-py3-none-any.whl (9.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size hypothesis-graphql-0.5.1.tar.gz (9.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page