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 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
    ...

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

Uploaded Source

Built Distribution

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

hypothesis_graphql-0.6.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis-graphql-0.6.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for hypothesis-graphql-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0faba624362bc173a3b7f77fc70fbcddb182e7a1f33c8a115950eb906a71ea62
MD5 19925cd9736acbe374eef4aa3b33518c
BLAKE2b-256 68267e8ddf44b3defd2150c6728a267e64543831668ce6a59428c8fe33dc831d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hypothesis_graphql-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9922512472351e3485fa2ce1b1697df99b8813ac7e33ddbfa03e1b839bde3017
MD5 8ba481dc585c4bdb6ca931ac20c0fa73
BLAKE2b-256 24130afb9e273dbbcf8c83d1801a6fe6830d57232d33676ef2d964e7e0fae04a

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