Skip to main content

A strawberry graphql schema wrapper with operation autogeneration.

Project description

Overview

strawberry-autograph is a testing library designed to extend Strawberry's test client capabilities by automatically generating operation strings for queries and mutations. This allows for streamlined testing of GraphQL schemas, focusing on testing schema logic directly with Strawberry input objects.

Installation

Add strawberry-autograph to your project using Poetry or pip:

poetry add strawberry-autograph

or

pip install strawberry-autograph

Ensure you have Strawberry GraphQL installed as it's an optional dependency:

poetry add strawberry-graphql

Features

  • Operation Autogeneration: Dynamically creates operation strings for testing.
  • Seamless Integration: Wraps around Strawberry's test client, enhancing its functionality.

Usage

strawberry-autograph simplifies writing tests for Strawberry schemas by using defined inputs directly in test cases.

Testing Mutations with Inputs

Define your schema with a mutation that takes a Strawberry input:

import strawberry

@strawberry.input
class CookEggInput:
    minutes: int

@strawberry.type
class Mutation:
    @strawberry.mutation
    def cook_egg(self, egg_op: CookEggInput) -> str:
        return "cooked" if input.minutes > 3 else "raw"

schema = strawberry.Schema(mutation=Mutation)

Use strawberry-autograph to automatically generate the mutation operation string and execute it with the Strawberry test client:

from strawberry_autograph import AutoGraphClient
from myapp.schema import schema  # Your Strawberry graphql schema object

def test_cook_egg():
    client = AutoGraphClient(schema)
    result = client.cook_egg(
        egg_op=CookEggInput(minutes=4)
    )
    assert result.data == {"cookEgg": "cooked"}

This library enables focused and efficient testing of GraphQL logic, directly utilizing Strawberry types and inputs.

Development Status

strawberry-autograph is currently in alpha (v0.1.0) and open to contributions. As an evolving project, feedback and improvements are welcome to refine its functionality and user experience.

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

strawberry_autograph-0.1.0.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

strawberry_autograph-0.1.0-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

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