File: test_schema.py

package info (click to toggle)
strawberry-graphql-django 0.62.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,968 kB
  • sloc: python: 27,530; sh: 17; makefile: 16
file content (46 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pathlib
from typing import Optional

import strawberry
from pytest_snapshot.plugin import Snapshot

import strawberry_django
from strawberry_django import mutations

from .models import Issue, Milestone, Project
from .schema import IssueInput, IssueType, MilestoneType, ProjectType, schema

SNAPSHOTS_DIR = pathlib.Path(__file__).parent / "snapshots"


def test_schema(snapshot: Snapshot):
    snapshot.snapshot_dir = SNAPSHOTS_DIR
    snapshot.assert_match(str(schema), "schema.gql")


def test_schema_with_inheritance(snapshot: Snapshot):
    @strawberry_django.type(Project)
    class ProjectTypeSubclass(ProjectType): ...

    @strawberry_django.type(Milestone)
    class MilestoneTypeSubclass(MilestoneType): ...

    @strawberry_django.input(Issue)
    class IssueInputSubclass(IssueInput): ...

    @strawberry.type
    class Query:
        project: Optional[ProjectTypeSubclass] = strawberry_django.node()
        milestone: Optional[MilestoneTypeSubclass] = strawberry_django.node()

    @strawberry.type
    class Mutation:
        create_issue: IssueType = mutations.create(
            IssueInputSubclass,
            handle_django_errors=True,
            argument_name="input",
        )

    schema = strawberry.Schema(query=Query, mutation=Mutation)
    snapshot.snapshot_dir = SNAPSHOTS_DIR
    snapshot.assert_match(str(schema), "schema_with_inheritance.gql")