Skip to content

Commit 01c86b3

Browse files
ewen-lorimerEwen Lorimer
andauthored
Fix snake cased gql field names (#377)
* Fixed hatch coverage flag * Updated class field generator to use original field name from gql schema, instead of snake-cased field names * Updated expected clients to reflect the changes made to the field generator --------- Co-authored-by: Ewen Lorimer <[email protected]>
1 parent cf19fb9 commit 01c86b3

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

ariadne_codegen/client_generators/custom_fields.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _generate_class_field(
216216
"""Handles the generation of field types."""
217217
if getattr(field, "args") or method_required:
218218
return self.generate_product_type_method(
219-
name, field_name, getattr(field, "args")
219+
name, field_name, org_name, getattr(field, "args")
220220
)
221221
return generate_ann_assign(
222222
target=generate_name(name),
@@ -311,7 +311,11 @@ def _generate_on_method(self, class_name: str) -> ast.FunctionDef:
311311
)
312312

313313
def generate_product_type_method(
314-
self, name: str, class_name: str, arguments: Optional[Dict[str, Any]] = None
314+
self,
315+
name: str,
316+
class_name: str,
317+
org_name: str,
318+
arguments: Optional[Dict[str, Any]] = None,
315319
) -> ast.FunctionDef:
316320
"""Generates a method for a product type."""
317321
arguments = arguments or {}
@@ -343,7 +347,7 @@ def generate_product_type_method(
343347
generate_return(
344348
value=generate_call(
345349
func=field_class_name,
346-
args=[generate_constant(name)],
350+
args=[generate_constant(org_name)],
347351
keywords=arguments_keyword,
348352
)
349353
),

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ features = ["dev", "types"]
7979
check = [
8080
"hatch fmt",
8181
"hatch test -a -p",
82-
"hatch test --coverage",
82+
"hatch test --cover",
8383
"hatch run types:check",
8484
]
8585

tests/main/clients/custom_query_builder/expected_client/custom_fields.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def alias(self, alias: str) -> "MetadataItemFields":
9797
class ObjectWithMetadataInterface(GraphQLField):
9898
@classmethod
9999
def private_metadata(cls) -> "MetadataItemFields":
100-
return MetadataItemFields("private_metadata")
100+
return MetadataItemFields("privateMetadata")
101101

102102
@classmethod
103103
def private_metafield(cls, key: str) -> "ObjectWithMetadataGraphQLField":
@@ -108,7 +108,7 @@ def private_metafield(cls, key: str) -> "ObjectWithMetadataGraphQLField":
108108
key: value for key, value in arguments.items() if value["value"] is not None
109109
}
110110
return ObjectWithMetadataGraphQLField(
111-
"private_metafield", arguments=cleared_arguments
111+
"privateMetafield", arguments=cleared_arguments
112112
)
113113

114114
@classmethod
@@ -166,7 +166,7 @@ class ProductFields(GraphQLField):
166166

167167
@classmethod
168168
def private_metadata(cls) -> "MetadataItemFields":
169-
return MetadataItemFields("private_metadata")
169+
return MetadataItemFields("privateMetadata")
170170

171171
@classmethod
172172
def private_metafield(cls, key: str) -> "ProductGraphQLField":
@@ -176,7 +176,7 @@ def private_metafield(cls, key: str) -> "ProductGraphQLField":
176176
cleared_arguments = {
177177
key: value for key, value in arguments.items() if value["value"] is not None
178178
}
179-
return ProductGraphQLField("private_metafield", arguments=cleared_arguments)
179+
return ProductGraphQLField("privateMetafield", arguments=cleared_arguments)
180180

181181
@classmethod
182182
def metadata(cls) -> "MetadataItemFields":
@@ -211,7 +211,7 @@ def edges(cls) -> "ProductCountableEdgeFields":
211211

212212
@classmethod
213213
def page_info(cls) -> "PageInfoFields":
214-
return PageInfoFields("page_info")
214+
return PageInfoFields("pageInfo")
215215

216216
total_count: "ProductCountableConnectionGraphQLField" = (
217217
ProductCountableConnectionGraphQLField("totalCount")
@@ -290,7 +290,7 @@ def alias(self, alias: str) -> "ProductTranslatableContentFields":
290290
class ProductTypeCountableConnectionFields(GraphQLField):
291291
@classmethod
292292
def page_info(cls) -> "PageInfoFields":
293-
return PageInfoFields("page_info")
293+
return PageInfoFields("pageInfo")
294294

295295
def fields(
296296
self,
@@ -308,7 +308,7 @@ def alias(self, alias: str) -> "ProductTypeCountableConnectionFields":
308308
class TranslatableItemConnectionFields(GraphQLField):
309309
@classmethod
310310
def page_info(cls) -> "PageInfoFields":
311-
return PageInfoFields("page_info")
311+
return PageInfoFields("pageInfo")
312312

313313
@classmethod
314314
def edges(cls) -> "TranslatableItemEdgeFields":
@@ -357,7 +357,7 @@ def alias(self, alias: str) -> "TranslatableItemEdgeFields":
357357
class UpdateMetadataFields(GraphQLField):
358358
@classmethod
359359
def metadata_errors(cls) -> "MetadataErrorFields":
360-
return MetadataErrorFields("metadata_errors")
360+
return MetadataErrorFields("metadataErrors")
361361

362362
@classmethod
363363
def errors(cls) -> "MetadataErrorFields":

tests/main/clients/custom_sync_query_builder/expected_client/custom_fields.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def alias(self, alias: str) -> "MetadataItemFields":
9797
class ObjectWithMetadataInterface(GraphQLField):
9898
@classmethod
9999
def private_metadata(cls) -> "MetadataItemFields":
100-
return MetadataItemFields("private_metadata")
100+
return MetadataItemFields("privateMetadata")
101101

102102
@classmethod
103103
def private_metafield(cls, key: str) -> "ObjectWithMetadataGraphQLField":
@@ -108,7 +108,7 @@ def private_metafield(cls, key: str) -> "ObjectWithMetadataGraphQLField":
108108
key: value for key, value in arguments.items() if value["value"] is not None
109109
}
110110
return ObjectWithMetadataGraphQLField(
111-
"private_metafield", arguments=cleared_arguments
111+
"privateMetafield", arguments=cleared_arguments
112112
)
113113

114114
@classmethod
@@ -166,7 +166,7 @@ class ProductFields(GraphQLField):
166166

167167
@classmethod
168168
def private_metadata(cls) -> "MetadataItemFields":
169-
return MetadataItemFields("private_metadata")
169+
return MetadataItemFields("privateMetadata")
170170

171171
@classmethod
172172
def private_metafield(cls, key: str) -> "ProductGraphQLField":
@@ -176,7 +176,7 @@ def private_metafield(cls, key: str) -> "ProductGraphQLField":
176176
cleared_arguments = {
177177
key: value for key, value in arguments.items() if value["value"] is not None
178178
}
179-
return ProductGraphQLField("private_metafield", arguments=cleared_arguments)
179+
return ProductGraphQLField("privateMetafield", arguments=cleared_arguments)
180180

181181
@classmethod
182182
def metadata(cls) -> "MetadataItemFields":
@@ -211,7 +211,7 @@ def edges(cls) -> "ProductCountableEdgeFields":
211211

212212
@classmethod
213213
def page_info(cls) -> "PageInfoFields":
214-
return PageInfoFields("page_info")
214+
return PageInfoFields("pageInfo")
215215

216216
total_count: "ProductCountableConnectionGraphQLField" = (
217217
ProductCountableConnectionGraphQLField("totalCount")
@@ -290,7 +290,7 @@ def alias(self, alias: str) -> "ProductTranslatableContentFields":
290290
class ProductTypeCountableConnectionFields(GraphQLField):
291291
@classmethod
292292
def page_info(cls) -> "PageInfoFields":
293-
return PageInfoFields("page_info")
293+
return PageInfoFields("pageInfo")
294294

295295
def fields(
296296
self,
@@ -308,7 +308,7 @@ def alias(self, alias: str) -> "ProductTypeCountableConnectionFields":
308308
class TranslatableItemConnectionFields(GraphQLField):
309309
@classmethod
310310
def page_info(cls) -> "PageInfoFields":
311-
return PageInfoFields("page_info")
311+
return PageInfoFields("pageInfo")
312312

313313
@classmethod
314314
def edges(cls) -> "TranslatableItemEdgeFields":
@@ -357,7 +357,7 @@ def alias(self, alias: str) -> "TranslatableItemEdgeFields":
357357
class UpdateMetadataFields(GraphQLField):
358358
@classmethod
359359
def metadata_errors(cls) -> "MetadataErrorFields":
360-
return MetadataErrorFields("metadata_errors")
360+
return MetadataErrorFields("metadataErrors")
361361

362362
@classmethod
363363
def errors(cls) -> "MetadataErrorFields":

0 commit comments

Comments
 (0)