Skip to content

fix(laravel): register graphql routes before catch-all entrypoint#8248

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/laravel-graphql-route-order-8128
Jun 5, 2026
Merged

fix(laravel): register graphql routes before catch-all entrypoint#8248
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/laravel-graphql-route-order-8128

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 5, 2026

Summary

With api-platform.defaults.route_prefix='', Laravel's route matcher hit the catch-all entrypoint /{index?}{_format?} before /graphql, stripping the leading g as the optional index parameter. GET /graphql and /graphiql resolved to the entrypoint controller and returned a format error. Reordering the GraphQL/GraphiQL registrations to run before the entrypoint group restores correct matching.

Reproduction

Set api-platform.defaults.route_prefix='' and GET /graphql — got Format "raphql" is not supported instead of the GraphQL playground.

Test plan

  • Added failing tests covering empty route prefix for POST /graphql, GET /graphql, GET /graphiql.
  • Tests pass after the fix.
  • No regressions in Laravel suite.

Fixes #8128

When api-platform.defaults.route_prefix is set to an empty string, the
catch-all entrypoint route /{index?}{_format?} is registered before
/graphql and /graphiql. Laravel matches routes in registration order, so
GET requests to /graphql are captured by the entrypoint controller and
fail with `Format "raphql" is not supported` (the leading `g` is stripped
as the optional `index` parameter). Moving the GraphQL/GraphiQL route
registrations ahead of the entrypoint group fixes the match regardless
of the prefix value. With a non-empty prefix (e.g. /api) there is no
overlap, so behavior is unchanged.

Fixes api-platform#8128
@soyuka soyuka merged commit 149adf7 into api-platform:4.3 Jun 5, 2026
109 of 112 checks passed
@soyuka soyuka deleted the fix/laravel-graphql-route-order-8128 branch June 5, 2026 09:52
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