Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

284-fixed-creating-fragments-using-interface #291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.14.0 (Unreleased)

- Re-added `model_rebuild` calls for input types with forward references.
- Fixed fragments on interfaces being omitted from generated client.


## 0.13.0 (2024-03-4)
Expand Down
24 changes: 22 additions & 2 deletions ariadne_codegen/client_generators/result_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,12 @@ def _resolve_selection_set(
fields.extend(sub_fields)
fragments = fragments.union(sub_fragments)
elif isinstance(selection, InlineFragmentNode):
if selection.type_condition.name.value == root_type:
root_type_value = self._get_inline_fragment_root_type(
selection.type_condition.name.value, root_type
)
if root_type_value:
sub_fields, sub_fragments = self._resolve_selection_set(
selection.selection_set, root_type
selection.selection_set, root_type_value
)
fields.extend(sub_fields)
fragments = fragments.union(sub_fragments)
Expand All @@ -337,6 +340,23 @@ def _resolve_selection_set(
)
return fields, fragments

def _get_inline_fragment_root_type(
self, selection_value: str, root_type: str
) -> Optional[str]:
type_ = self.schema.type_map.get(root_type)
if not type_:
return None

if isinstance(type_, GraphQLObjectType) and selection_value in {
interface.name for interface in type_.interfaces
}:
return selection_value

if selection_value == root_type:
return root_type

return None

def _unpack_fragment(
self,
fragment_def: FragmentDefinitionNode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from .async_base_client import AsyncBaseClient
from .base_model import BaseModel, Upload
from .client import Client
from .exceptions import (
GraphQLClientError,
GraphQLClientGraphQLError,
GraphQLClientGraphQLMultiError,
GraphQLClientHttpError,
GraphQLClientInvalidResponseError,
)
from .fragments import Item, ItemError
from .my_mutation import (
MyMutation,
MyMutationChangeItem,
MyMutationChangeItemContacts,
MyMutationChangeItemErrorsItemServiceInternalError,
)

__all__ = [
"AsyncBaseClient",
"BaseModel",
"Client",
"GraphQLClientError",
"GraphQLClientGraphQLError",
"GraphQLClientGraphQLMultiError",
"GraphQLClientHttpError",
"GraphQLClientInvalidResponseError",
"Item",
"ItemError",
"MyMutation",
"MyMutationChangeItem",
"MyMutationChangeItemContacts",
"MyMutationChangeItemErrorsItemServiceInternalError",
"Upload",
]
Loading
Loading