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 details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file strawberry_autograph-0.1.0.tar.gz.

File metadata

  • Download URL: strawberry_autograph-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.6 Darwin/23.2.0

File hashes

Hashes for strawberry_autograph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43d481f472b7047d93c738cdaab3720f3fab744b0203cadb745d2134c97fd651
MD5 eb975ac6414e09303d6439d50b461697
BLAKE2b-256 40b7881279dfddb50a04b3beeeda86a1a1ed031e979799f50301cf5dfe21d976

See more details on using hashes here.

File details

Details for the file strawberry_autograph-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for strawberry_autograph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5457bb98b88d8bc7e290004dfa7b69c3617034c741e3958ea12eaa09e3af4805
MD5 218b9827edddde59ea90cd3d711d0ab0
BLAKE2b-256 a691c951ea27309bffdb556b52c0b5b405cf59c2b3279c5a641370a8e8bc3a73

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