Skip to content

Commit

Permalink
Merge branch 'main' into fix/include-directive-result-type
Browse files Browse the repository at this point in the history
  • Loading branch information
salmannotkhan authored Apr 21, 2024
2 parents f4c1339 + 05353b7 commit 8063b7e
Show file tree
Hide file tree
Showing 15 changed files with 694 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- Added `ClientForwardRefsPlugin` to standard plugins.
- Re-added `model_rebuild` calls for input types with forward references.
- Fixed `@Include` directive result type when using `convert_to_snake_case` option
- Fixed fragments on interfaces being omitted from generated client.
- Fixed `@Include` directive result type when using `convert_to_snake_case` option.


## 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 @@ -327,9 +327,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 @@ -338,6 +341,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

0 comments on commit 8063b7e

Please sign in to comment.