skillfed

hypothesis-graphql

Hypothesis strategies for GraphQL queries

hypothesis-graphql v0.13.1 2.9M downloads/30d#2,840 on PyPI48
Permissive license MIT Active released

What it is and what it does

hypothesis-graphql is a Hypothesis strategy library that generates valid (and optionally invalid) GraphQL queries matching your schema. It integrates with Hypothesis's property-based testing framework to create parametrized test cases with arbitrary query depth and field combinations, helping you find edge cases and error-handling gaps in your GraphQL backend that manual test cases might miss.

The library works by taking a GraphQL schema as input and returning a Hypothesis strategy that produces random but schema-compliant queries. You can customize generation via field restrictions, string encoding options, and custom scalar mappings. It also supports negative testing mode to generate intentionally invalid queries for validating your server's error handling.

Use it for:

  • Test a GraphQL API for crashes or unexpected behavior by generating thousands of random valid queries automatically.
  • Validate error handling in your GraphQL server by generating invalid queries (wrong types, missing required args, null for non-null fields).
  • Restrict query generation to specific fields to focus testing on a particular part of your schema.
  • Generate custom scalar values (e.g., dates, UUIDs) that match your schema's domain constraints.
  • Discover edge cases in nested query resolution that are unlikely to be covered by hand-written test cases.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Generates arbitrary GraphQL queries matching your schema to use as property-based test cases via Hypothesis, exposing edge cases in your GraphQL backend.

Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real testing problem—finding edge cases in GraphQL backends through property-based testing. It integrates cleanly with Hypothesis and supports both positive and negative test generation. Recommended for any project with a GraphQL API that needs robust backend validation.

Install

hypothesis-graphql on PyPI

pip

pip install hypothesis-graphql

uv

uv add hypothesis-graphql

poetry

poetry add hypothesis-graphql

Installing hypothesis-graphql

Before you install

Low friction: pure Python wheel with only two runtime dependencies (graphql-core and hypothesis). Actively maintained with a release 31 days ago and no known vulnerabilities.

License in practice

MIT license (permissive) — you can use this freely in commercial and open-source projects with minimal restrictions.

Quickstart

from hypothesis import given
from hypothesis_graphql import from_schema

SCHEMA = "type Query { getBooks: [String] }"

@given(from_schema(SCHEMA))
def test_graphql(query):
    # query is a generated GraphQL string
    response = requests.post("http://localhost/graphql", json={"query": query})
    assert response.status_code == 200

Requires Python 3.10 or later.

Verify before relying

  • Whether the library supports all GraphQL spec features (subscriptions, directives, interfaces, unions) or has known limitations.
  • Performance characteristics when generating queries against very large schemas.
  • Whether custom scalar strategies can handle complex nested types beyond the documented examples.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — graphql-core, hypothesis
Maintenance actively maintained — 31 days since the last release
Last repo commit
First released
Downloads 2,888,327/month — #2,840 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: hypothesis_graphql-0.13.1-py3-none-any.whl

Keywords: graphql, hypothesis, testing

Development Status :: 4 - BetaEnvironment :: ConsoleFramework :: HypothesisIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: Testing

Tags

graphql query generation testinghypothesis graphql strategiesproperty-based testing graphqlgraphql schema test datagraphql fuzz testinggraphql negative testinggraphql backend validation
property-based-testinggraphqlfuzz-testing

More Testing packages