Skip to main content

Hypothesis strategies for GraphQL schemas and queries

Project description

Build codecov.io 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.

Usage

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


@given(query=gql_st.query(SCHEMA))
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.

Source Distribution

hypothesis-graphql-0.5.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

hypothesis_graphql-0.5.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file hypothesis-graphql-0.5.0.tar.gz.

File metadata

  • Download URL: hypothesis-graphql-0.5.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for hypothesis-graphql-0.5.0.tar.gz
Algorithm Hash digest
SHA256 94193989cd3282422ee2e7fa50b486db7f33631e52f258d150ea20d327f081ac
MD5 592851e3f2d5374d613fcd0f57912753
BLAKE2b-256 ada1c9d61a53c3e4a08cfbf59d6ffa4cfee1795c5282aea91043d642316bb78d

See more details on using hashes here.

File details

Details for the file hypothesis_graphql-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: hypothesis_graphql-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for hypothesis_graphql-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63e1ddf207cd86ebf957d9bb801c3761b2c2ac6dad67f31494e54549d786f97a
MD5 10c4af7077dfc202eeee5d9ba668b032
BLAKE2b-256 6dc9ee57d62e5e7a1c7be6e4c6057cfc9ce848834a2ea8eb7aca9a5544fa8805

See more details on using hashes here.

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