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.4.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

hypothesis_graphql-0.4.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis-graphql-0.4.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.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.4.1.tar.gz
Algorithm Hash digest
SHA256 281c4b7cb7581623ab0cc65dfbdb7f117ef51e26075780b776b778dbb0338bc1
MD5 b826203195ce67e88695ebbb687c5ec2
BLAKE2b-256 d1f08cdc8c7a7d4f85e6860a7f70f9fb778ab32174745ececa5cd91e8fce68bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypothesis_graphql-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.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.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80793a76b814b8b65695f4ca2e48ad4c96af986cca7ecda8503c5b08ce55b8cb
MD5 4a1dc829062780130bbf2ab7233b085e
BLAKE2b-256 cf4369f3a8e7aa33aae19ebab825fbde74a995fff5589dc4024dbbb8555c789d

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