Repository: mirumee/ariadne-codegen (python)
Issue: GQL operation string is missing fragment used in a query
For the given GQL schema:
```graphql
type ItemA {
  valueA: String
}

type ItemB {
  valueB: String
}

union Item = ItemA | ItemB

type Container {
  name: String
  items: [Item]
}

type Query {
  container(id: ID!): Container
}
```

and following query:
```graphql
fragment ItemAFragment on ItemA {
  valueA
}

fragment ItemBFragment on ItemB {
  valueB
}

fragment ItemFragment on Item {
  ... on ItemA {
    ...ItemAFragment
  }
  ... on ItemB {
    ...ItemBFragment
  }
}

fragment ContainerFragment on Container {
  name
  items {
    ...ItemFragment
  }
}

query getContainer($id: ID!) {
  container(id: $id) {
    ...ContainerFragment  
  }
}
```

the generated client contains the following `get_container` method:
```python
...
    async def get_container(self, id: str) -> GetContainer:
        query = gql(
            """
            query getContainer($id: ID!) {
              container(id: $id) {
                ...ContainerFragment
              }
            }

            fragment ContainerFragment on Container {
              name
              items {
                ...ItemFragment
              }
            }

            fragment ItemFragment on Item {
              ... on ItemA {
                ...ItemAFragment
              }
              ... on ItemB {
                ...ItemBFragment
              }
            }
            """
        )
...
```

Operation string is missing `ItemAFragment` and `ItemBFragment` definitions, even though they are used in `ItemFragment`.
Pull request description: Fix generating operation string for nested inline fragments
Resolves #202 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2b48dd..4b3e349 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
 # CHANGELOG
 
+## UNRELEASED
+
+- Fixed generating operation string for nested inline fragments.
+
+
 ## 0.8.0 (2023-08-22)
 
 - Added support for `Upload` scalar. Added support for file uploads to `AsyncBaseClient` and `BaseClient`.
diff --git a/ariadne_codegen/client_generators/result_types.py b/ariadne_codegen/client_generators/result_types.py
index 8415ddc..e806602 100644
--- a/ariadne_codegen/client_generators/result_types.py
+++ b/ariadne_codegen/client_generators/result_types.py
@@ -570,7 +570,9 @@ class ResultTypesGenerator:
                         self.fragments_definitions[name].selection_set
                     )
                 )
-            elif isinstance(node, FieldNode) and node.selection_set:
+            elif (
+                isinstance(node, (FieldNode, InlineFragmentNode)) and node.selection_set
+            ):
                 names = names.union(self._get_fragments_names(node.selection_set))
         return names
 


Test patch:
diff --git a/tests/client_generators/result_types_generator/schema.py b/tests/client_generators/result_types_generator/schema.py
index a0932d0..1e5fa4e 100644
--- a/tests/client_generators/result_types_generator/schema.py
+++ b/tests/client_generators/result_types_generator/schema.py
@@ -32,6 +32,7 @@ type CustomType {
   _field4: String!
   _Field5: String!
   scalarField: SCALARA
+  unionField: UnionType!
   _: String!
   schema: String!
 }
diff --git a/tests/client_generators/result_types_generator/test_get_operation_as_str.py b/tests/client_generators/result_types_generator/test_get_operation_as_str.py
index ab86d56..9cda3d5 100644
--- a/tests/client_generators/result_types_generator/test_get_operation_as_str.py
+++ b/tests/client_generators/result_types_generator/test_get_operation_as_str.py
@@ -164,6 +164,65 @@ def test_get_operation_as_str_returns_str_with_fragment_used_by_another_fragment
     assert "fragment NestedFragment on CustomType2" in result
 
 
+def test_get_operation_as_str_returns_fragment_used_within_nested_inline_fragment():
+    query_str = """
+        query CustomQuery {
+            query2 {
+                id
+                ...OuterFragment
+            }
+        }
+    """
+    outer_fragment = """
+        fragment OuterFragment on CustomType {
+            unionType {
+                ... on CustomType1 {
+                    ...InnerFragment1
+                }
+                ... on CustomType2 {
+                    ...InnerFragment2
+                }
+            }
+        }
+    """
+    inner_fragment1 = """
+        fragment InnerFragment1 on CustomType1 {
+            fielda
+        }
+    """
+    inner_fragment2 = """
+        fragment InnerFragment2 on CustomType2 {
+            fieldb
+        }
+    """
+
+    generator = ResultTypesGenerator(
+        schema=build_ast_schema(parse(SCHEMA_STR)),
+        operation_definition=cast(
+            OperationDefinitionNode, parse(query_str).definitions[0]
+        ),
+        enums_module_name="enums",
+        scalars_module_name="scalars",
+        fragments_definitions={
+            "OuterFragment": cast(
+                FragmentDefinitionNode, parse(outer_fragment).definitions[0]
+            ),
+            "InnerFragment1": cast(
+                FragmentDefinitionNode, parse(inner_fragment1).definitions[0]
+            ),
+            "InnerFragment2": cast(
+                FragmentDefinitionNode, parse(inner_fragment2).definitions[0]
+            ),
+        },
+    )
+
+    result = generator.get_operation_as_str()
+
+    assert "fragment OuterFragment on CustomType" in result
+    assert "fragment InnerFragment1 on CustomType1" in result
+    assert "fragment InnerFragment2 on CustomType2" in result
+
+
 def test_get_operation_as_str_returns_operation_without_mixin_directive():
     query_str = """
         query CustomQuery {