Skip to content

Commit

Permalink
Expose fragments as a property on Info
Browse files Browse the repository at this point in the history
  • Loading branch information
cpd67 committed Dec 6, 2023
1 parent 6b84220 commit efc51b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Exposes fragments as a property on Info, which lets you access queried for fragments without having to go through _raw_info.
6 changes: 5 additions & 1 deletion strawberry/types/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

if TYPE_CHECKING:
from graphql import GraphQLResolveInfo, OperationDefinitionNode
from graphql.language import FieldNode
from graphql.language import FieldNode, FragmentDefinitionNode
from graphql.pyutils.path import Path

from strawberry.arguments import StrawberryArgument
Expand Down Expand Up @@ -73,6 +73,10 @@ def root_value(self) -> RootValueType:
def variable_values(self) -> Dict[str, Any]:
return self._raw_info.variable_values

@property
def fragments(self) -> Dict[str, FragmentDefinitionNode]:
return self._raw_info.fragments

Check warning on line 78 in strawberry/types/info.py

View check run for this annotation

Codecov / codecov/patch

strawberry/types/info.py#L78

Added line #L78 was not covered by tests

@property
def return_type(
self,
Expand Down
5 changes: 5 additions & 0 deletions tests/schema/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Result:
operation: str
path: str
variable_values: str
fragments: str

Check warning on line 27 in tests/schema/test_info.py

View check run for this annotation

Codecov / codecov/patch

tests/schema/test_info.py#L27

Added line #L27 was not covered by tests
context_equal: bool
root_equal: bool
return_type: str
Expand All @@ -40,6 +41,7 @@ def hello_world(self, info: Info[str, str]) -> Result:
python_name=info.python_name,
selected_field=json.dumps(dataclasses.asdict(*info.selected_fields)),
variable_values=str(info.variable_values),
fragments=str(info.fragments),
context_equal=info.context == my_context,
root_equal=info.root_value == root_value,
return_type=str(info.return_type),
Expand All @@ -53,6 +55,7 @@ def hello_world(self, info: Info[str, str]) -> Result:
fieldName
pythonName
selectedField
fragments
contextEqual
operation
path
Expand All @@ -77,6 +80,7 @@ def hello_world(self, info: Info[str, str]) -> Result:
"operation",
"contextEqual",
"variableValues",
"fragments",
"returnType",
"fieldName",
"pythonName",
Expand All @@ -95,6 +99,7 @@ def hello_world(self, info: Info[str, str]) -> Result:
"contextEqual": True,
"rootEqual": True,
"variableValues": "{}",
"fragments": "{}",
"returnType": "<class 'tests.schema.test_info.test_info_has_the_correct_shape.<locals>.Result'>",
"schemaPrint": schema.as_str(),
}
Expand Down

0 comments on commit efc51b5

Please sign in to comment.