-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for declaring and using interfaces (#55)
Add support for declaring and using interfaces
- Loading branch information
Showing
5 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Release Type: minor | ||
|
||
Added support for declaring interface by using `@strawberry.interface` | ||
|
||
Example: | ||
|
||
```python | ||
@strawberry.interface | ||
class Node: | ||
id: strawberry.ID | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
IS_STRAWBERRY_FIELD = "_is_strawberry_field" | ||
IS_STRAWBERRY_INPUT = "_is_strawberry_input" | ||
IS_STRAWBERRY_INTERFACE = "_is_strawberry_interface" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import textwrap | ||
|
||
import strawberry | ||
|
||
|
||
def test_interface(): | ||
@strawberry.interface | ||
class Node: | ||
id: strawberry.ID | ||
|
||
expected_representation = """ | ||
interface Node { | ||
id: ID! | ||
} | ||
""" | ||
|
||
assert repr(Node("a")) == textwrap.dedent(expected_representation).strip() | ||
|
||
|
||
def test_implementing_interface(): | ||
@strawberry.interface | ||
class Node: | ||
id: strawberry.ID | ||
|
||
@strawberry.type | ||
class Post(Node): | ||
title: str | ||
|
||
expected_representation = """ | ||
type Post implements Node { | ||
id: ID! | ||
title: String! | ||
} | ||
""" | ||
|
||
assert repr(Post("a", "abc")) == textwrap.dedent(expected_representation).strip() |