Skip to content

IFC-2536: Update generate return types to inject typename into schema#997

Open
solababs wants to merge 1 commit intoinfrahub-developfrom
sb-07052026-update-generate-return-types-command-ifc-2536
Open

IFC-2536: Update generate return types to inject typename into schema#997
solababs wants to merge 1 commit intoinfrahub-developfrom
sb-07052026-update-generate-return-types-command-ifc-2536

Conversation

@solababs
Copy link
Copy Markdown
Contributor

@solababs solababs commented May 7, 2026

Why

infrahubctl generate return-types fails with a TypeError when the schema contains interface or union types. The root cause is in ariadne-codegen: it automatically injects __typename when generating models for abstract-typed fields, then looks up __typename in schema.type_map. Since __typename is a built-in meta-field and not a schema-defined field, the lookup misses and the codegen fallback tries to create a new GraphQLScalarType("String") — which raises TypeError because "String" is a reserved built-in scalar name in graphql-core.

This makes generate return-types unusable for any Infrahub schema that uses interfaces (which most real schemas do).

What changed

  • Behavioral: infrahubctl generate return-types now succeeds on schemas with interface or union types. Previously it raised TypeError: Duplicate type "String".

@solababs solababs requested a review from a team as a code owner May 7, 2026 09:42
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                Coverage Diff                @@
##           infrahub-develop     #997   +/-   ##
=================================================
  Coverage             81.43%   81.44%           
=================================================
  Files                   134      134           
  Lines                 11359    11365    +6     
  Branches               1703     1705    +2     
=================================================
+ Hits                   9250     9256    +6     
  Misses                 1566     1566           
  Partials                543      543           
Flag Coverage Δ
integration-tests 41.89% <28.57%> (-0.02%) ⬇️
python-3.10 54.42% <100.00%> (+<0.01%) ⬆️
python-3.11 54.43% <100.00%> (+0.02%) ⬆️
python-3.12 54.43% <100.00%> (+0.04%) ⬆️
python-3.13 54.43% <100.00%> (+0.02%) ⬆️
python-3.14 54.43% <100.00%> (+0.04%) ⬆️
python-filler-3.12 22.71% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/graphql.py 89.21% <100.00%> (+0.67%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! Is this a bug that should be reported to ariadne-codegen? I'm wondering if it might be fixed in a later version since the one we've pinned is a bit old.

Could be worth to upgrade to see if it resolves the issue, other than that based on the added code can we have some test that would fail if we removed this inject_typename?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants