Skip to content

fix(graphql): return identifier-only node on circular reference#8239

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/graphql-circular-ref-normalize-8080
Jun 4, 2026
Merged

fix(graphql): return identifier-only node on circular reference#8239
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/graphql-circular-ref-normalize-8080

Conversation

@soyuka

@soyuka soyuka commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

When a Doctrine entity has mutual ManyToOne/OneToMany references (e.g. Customer ↔ Address) and a GraphQL query traverses the cycle, the default Symfony circular_reference_handler returns the visited object's IRI as a string. The GraphQL ItemNormalizer and ObjectNormalizer then asserted the inner result was an array and threw Expected data to be an array., crashing the response with a 500.

This PR makes both normalizers return an identifier-only node (#itemResourceClass + #itemIdentifiers) when the inner normalize() yields a string, so the GraphQL field shape is preserved and the cycle is reported as already-visited instead of crashing.

Fixes #8080.

Test plan

  • tests/Functional/GraphQl/Issue8080Test.php — minimal reproduction with two ApiResource entities (Issue8080Customer, Issue8080Address) cross-referencing each other; query traverses the cycle and asserts no errors key in the response.
  • vendor/bin/phpunit tests/Functional/GraphQl — 148 tests, all green.
  • vendor/bin/phpunit src/GraphQl/Tests — 242 tests, all green.
  • vendor/bin/phpunit tests/Functional — 1564 tests, all green.
  • vendor/bin/phpstan analyse src/GraphQl/Serializer/ItemNormalizer.php src/GraphQl/Serializer/ObjectNormalizer.php — no errors.

@soyuka soyuka force-pushed the fix/graphql-circular-ref-normalize-8080 branch from 553ea23 to cb810f8 Compare June 4, 2026 14:36
Skip Issue8080 test on MongoDB — entities are ORM-only (no Document
equivalents). Avoids MappingException in MongoDB CI run.

Fixes api-platform#8080
@soyuka soyuka force-pushed the fix/graphql-circular-ref-normalize-8080 branch from cb810f8 to 0c852af Compare June 4, 2026 14:40
@soyuka soyuka merged commit d59c244 into api-platform:4.3 Jun 4, 2026
109 of 110 checks passed
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.

1 participant