Skip to content

Commit

Permalink
Fix oneOf introspection (#3528)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed May 31, 2024
1 parent 2f02b49 commit 62dd5ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
release type: patch

This release fixes an introspection issue when requesting `isOneOf` on built-in
scalars, like `String`.
6 changes: 6 additions & 0 deletions TWEET.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
馃啎 Release $version is out! Thanks to $contributor for the PR 馃憦

This release fixes an introspection issue when requesting `isOneOf` on built-in
scalars, like `String`.

Get it here 馃憠 $release_url
3 changes: 3 additions & 0 deletions strawberry/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ def _warn_for_federation_directives(self) -> None:

def _extend_introspection(self) -> None:
def _resolve_is_one_of(obj: Any, info: Any) -> bool:
if "strawberry-definition" not in obj.extensions:
return False

return obj.extensions["strawberry-definition"].is_one_of

instrospection_type = self._schema.type_map["__Type"]
Expand Down
17 changes: 17 additions & 0 deletions tests/schema/test_one_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,20 @@ def test_introspection():
assert not result.errors

assert result.data == {"__type": {"name": "ExampleInputTagged", "isOneOf": True}}


def test_introspection_builtin():
query = """
query {
__type(name: "String") {
name
isOneOf
}
}
"""

result = schema.execute_sync(query)

assert not result.errors

assert result.data == {"__type": {"name": "String", "isOneOf": False}}

0 comments on commit 62dd5ad

Please sign in to comment.