-
Notifications
You must be signed in to change notification settings - Fork 35
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
ClientForwardRefsPlugin
Error on generation
#313
Comments
In the above context: print(self.imported_classes)
>>> {'AsyncBaseClient': '.async_base_client', 'UNSET': '.base_model', 'UnsetType': '.base_model', 'Upload': '.base_model', 'GraphQLField': '.base_operation'} |
The code you're linking was changed in #306, do you have the same issue on latest main? If so, do you have a reproducible example or do you also get this on any of the two tests? |
The
[project]
name = "ard-test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"ariadne-codegen==0.14.0",
]
[tool.ariadne-codegen]
remote_schema_url = "https://countries.trevorblades.com"
enable_custom_operations = true
plugins = [
"ariadne_codegen.contrib.client_forward_refs.ClientForwardRefsPlugin",
]
|
Thanks. The example uses latest release ( I was going to run the tests for client forward refs on Python 3.12 but noticed that they never got added to the test fixture. I opened #314 to enable the tests |
I was conducting a feasibility test of this package and am new to GraphQL. My use of the plugin was driven by curiosity to understand how plugins affect the code. The issue I’ve raised is to highlight a case of execution failure, but I am not experiencing issues with using this package otherwise—it appears to be excellent. Attached are the diff results comparing two scenarios: one without any plugins and one with the To achieve this, I added some error-bypassing code to the library package, which I previously mentioned. diff --git a/graphql_client/client.py b/graphql_client/client.py
index dc5c970..8ff011b 100644
--- a/graphql_client/client.py
+++ b/graphql_client/client.py
@@ -16,7 +16,10 @@ from graphql import (
)
from .async_base_client import AsyncBaseClient
-from .base_operation import GraphQLField
+from .typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from ..base_operation import GraphQLField
def gql(q: str) -> str:
@@ -25,7 +28,10 @@ def gql(q: str) -> str:
class Client(AsyncBaseClient):
async def execute_custom_operation(
- self, *fields: GraphQLField, operation_type: OperationType, operation_name: str
+ self,
+ *fields: "GraphQLField",
+ operation_type: OperationType,
+ operation_name: str
) -> Dict[str, Any]:
selections = self._build_selection_set(fields)
combined_variables = self._combine_variables(fields)
@@ -43,7 +49,7 @@ class Client(AsyncBaseClient):
return self.get_data(response)
def _combine_variables(
- self, fields: Tuple[GraphQLField, ...]
+ self, fields: Tuple["GraphQLField", ...]
) -> Dict[str, Dict[str, Any]]:
variables_types_combined = {}
processed_variables_combined = {}
@@ -90,11 +96,13 @@ class Client(AsyncBaseClient):
)
def _build_selection_set(
- self, fields: Tuple[GraphQLField, ...]
+ self, fields: Tuple["GraphQLField", ...]
) -> List[SelectionNode]:
return [field.to_ast(idx) for idx, field in enumerate(fields)]
- async def query(self, *fields: GraphQLField, operation_name: str) -> Dict[str, Any]:
+ async def query(
+ self, *fields: "GraphQLField", operation_name: str
+ ) -> Dict[str, Any]:
return await self.execute_custom_operation(
*fields, operation_type=OperationType.QUERY, operation_name=operation_name
)
|
Summary
ariadne-codegen
: 0.14.0python
:ariadne-codegen/ariadne_codegen/contrib/client_forward_refs.py
Lines 176 to 188 in 11bfe35
Error log
Suggestion
ariadne-codegen/ariadne_codegen/contrib/client_forward_refs.py
Lines 176 to 188 in 11bfe35
The text was updated successfully, but these errors were encountered: