diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..5534c81417 --- /dev/null +++ b/RELEASE.md @@ -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. diff --git a/strawberry/types/info.py b/strawberry/types/info.py index 288957540d..d44563e246 100644 --- a/strawberry/types/info.py +++ b/strawberry/types/info.py @@ -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 @@ -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 + @property def return_type( self, diff --git a/tests/schema/test_info.py b/tests/schema/test_info.py index 989f0d7632..4eb3b66fb1 100644 --- a/tests/schema/test_info.py +++ b/tests/schema/test_info.py @@ -24,6 +24,7 @@ class Result: operation: str path: str variable_values: str + fragments: str context_equal: bool root_equal: bool return_type: str @@ -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), @@ -53,6 +55,7 @@ def hello_world(self, info: Info[str, str]) -> Result: fieldName pythonName selectedField + fragments contextEqual operation path @@ -77,6 +80,7 @@ def hello_world(self, info: Info[str, str]) -> Result: "operation", "contextEqual", "variableValues", + "fragments", "returnType", "fieldName", "pythonName", @@ -95,6 +99,7 @@ def hello_world(self, info: Info[str, str]) -> Result: "contextEqual": True, "rootEqual": True, "variableValues": "{}", + "fragments": "{}", "returnType": ".Result'>", "schemaPrint": schema.as_str(), }