-
Notifications
You must be signed in to change notification settings - Fork 38
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
include_all_inputs = false leads to IndexError in isort #308
Comments
Hi @weblab-misha, I know how to fix this issue, but I found it hard to recreate in my own schema. Could you provide a schema example so I can better understand where the issue lies? |
I'm experiencing this with the Github schema: https://docs.github.com/en/graphql/overview/public-schema What happens is that my queries use no enums, and you end up with an empty enums.py module. |
I'm working around this by using a dummy plugin. This simply removes the import isort
from ariadne_codegen.plugins.base import Plugin
orig = isort.code
EMPTY_ENUMS = "from .enums import \n"
def mocked_isort_code(code: str) -> str:
if EMPTY_ENUMS in code:
code = "".join([line for line in code.splitlines(True) if line != EMPTY_ENUMS])
return orig(code)
if isort.code is not mocked_isort_code:
isort.code = mocked_isort_code
class CustomPlugin(Plugin):
pass |
Here is a better version of the plugin; this simply drops the empty
|
So, essentially the problem originates here: ariadne-codegen/ariadne_codegen/client_generators/input_types.py Lines 84 to 87 in 11bfe35
Since it's safe to call if used_enums := self.get_used_enums():
self._imports.append(
generate_import_from(used_enums, self.enums_module, 1)
) |
Looking into a PR for this, I thought I'd start with an assertion: def generate_import_from(
names: List[str], from_: Optional[str] = None, level: int = 0
) -> ast.ImportFrom:
"""Generate import from statement."""
assert names, "Using ImportFrom with no names would produce invalid Python code"
return ast.ImportFrom(
module=from_, names=[ast.alias(n) for n in names], level=level
) and promptly, 58 tests fail and 3 error out. :-D Luckily, these are down to just two callsites. |
ariadne-codegen --config ariadne-codegen.toml
runs fine unless I addinclude_all_inputs = false
in myariadne-codegen.toml
file. With include_all_inputs = false command fails with error:BTW, nothing is wrong with
include_all_enums = false
, it doesn't cause any issues.UPD:
The text was updated successfully, but these errors were encountered: