Skip to content

Commit

Permalink
Add tests for typenames and aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
enoua5 committed Sep 28, 2024
1 parent d926ba4 commit b2094c4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/codegen/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ def list_life() -> LifeContainer[Person, Animal]:
return LifeContainer([person], [dinosaur])

@strawberry.field
def one_of(value: OneOfInput) -> str:
def one_of(self, value: OneOfInput) -> str:
return "some value"

Check warning on line 138 in tests/codegen/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/codegen/conftest.py#L138

Added line #L138 was not covered by tests

@strawberry.field
def one_of_typename(self, value: OneOfInput) -> PersonOrAnimal:
return Person(name="Name", age=22)

Check warning on line 142 in tests/codegen/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/codegen/conftest.py#L142

Added line #L142 was not covered by tests


@strawberry.input
class BlogPostInput:
Expand Down
8 changes: 8 additions & 0 deletions tests/codegen/queries/oneof_typename.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query OneOfTypenameTest($value: OneOfInput!) {
alias: oneOfTypename(value: $value) {
... on Person {
name
age
}
}
}
19 changes: 19 additions & 0 deletions tests/codegen/snapshots/python/oneof_typename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Union

class OneOfTypenameTestResultOneOfTypenamePerson:
# typename: Person
name: str
age: int

class OneOfTypenameTestResult:
# alias for one_of_typename
alias: OneOfTypenameTestResultOneOfTypenamePerson

class OneOfInputA:
a: str
class OneOfInputB:
b: str
OneOfInput = Union[OneOfInputA,OneOfInputB]

class OneOfTypenameTestVariables:
value: OneOfInput
21 changes: 21 additions & 0 deletions tests/codegen/snapshots/typescript/oneof_typename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type OneOfTypenameTestResultOneOfTypenamePerson = {
name: string
age: number
}

type OneOfTypenameTestResult = {
// alias for one_of_typename
alias: OneOfTypenameTestResultOneOfTypenamePerson
}

type OneOfInput = {
a: string,
b: never
} | {
a: never,
b: string
}

type OneOfTypenameTestVariables = {
value: OneOfInput
}

0 comments on commit b2094c4

Please sign in to comment.