Skip to main content

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 a few strategies for different use cases.

  1. Schema generation - hypothesis_graphql.strategies.schemas()

  2. Query - hypothesis_graphql.strategies.queries(schema).

  3. Mutation - hypothesis_graphql.strategies.mutations(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]
}

type Mutation {
  addBook(title: String!, author: String!): Book!
  addAuthor(name: String!): 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.queries(SCHEMA))
def test_query(query):
    ...
    # This query might be generated:
    #
    # query {
    #   getBooks {
    #     title
    #   }
    # }


@given(mutation=gql_st.mutations(SCHEMA))
def test_mutation(mutation):
    ...
    # This mutation might be generated:
    #
    # mutation {
    #   addBook(title: "H4Z\u7869", author: "\u00d2"){
    #     title
    #   }
    # }

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

...


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

Release files for hypothesis-graphql 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hypothesis-graphql 0.6.0
File Size Uploaded
hypothesis-graphql-0.6.0.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hypothesis-graphql 0.6.0
File Interpreter ABI Platform
hypothesis_graphql-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / hypothesis-graphql-0.6.0.tar.gz

Download URL hypothesis-graphql-0.6.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0faba624362bc173a3b7f77fc70fbcddb182e7a1f33c8a115950eb906a71ea62
BLAKE2b-256 checksum
How to use checksums
68267e8ddf44b3defd2150c6728a267e64543831668ce6a59428c8fe33dc831d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / hypothesis_graphql-0.6.0-py3-none-any.whl

Download URL hypothesis_graphql-0.6.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9922512472351e3485fa2ce1b1697df99b8813ac7e33ddbfa03e1b839bde3017
BLAKE2b-256 checksum
How to use checksums
24130afb9e273dbbcf8c83d1801a6fe6830d57232d33676ef2d964e7e0fae04a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

0.13.1

2 release files

0.13.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

This release

0.6.0 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page