Skip to content
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

[GraphQL] Error with custom Filters #6746

Open
toitzi opened this issue Oct 24, 2024 · 1 comment
Open

[GraphQL] Error with custom Filters #6746

toitzi opened this issue Oct 24, 2024 · 1 comment

Comments

@toitzi
Copy link
Contributor

toitzi commented Oct 24, 2024

API Platform version(s) affected: 4.0.4

Description
I have a strange bug, which i am not Sure is Laravel unique, or an API-Platform issue or a graphql-php issue. To reproduce you should have the following setup:

  • Laravel API-Platform with graphql enabled
  • A Model with custom graphqlOperations, one of it beeing a custom parameter for a query collection (orderFilter - provided with this package):

image

I have applied those to my model called "Tenant". If i now visit the /api/graphql endpoint of my application to test it out, i can try that query:

image

( This query is schematically correct, and validated correctly by the UI)

However this will give me the following "funny" error, saying that "orderTenantcollection_query" is not a known type, and if i meant "orderTenantcollection_query" (the same lol):

image

To check why i checked the KnownTypeNames.php file of the graphql-php library. There is a check for $schema !== null && $schema->hasType($typeName) which resolves to false hence generating the error. However to generate the error message graphql-php get's a list of all possible types by calling $schema->getTypeMap() which will fully load all types (According to the function documentation this is not for production use since it does a full schema scan) and "orderTenantcollection_query" will be included there. A check for $schema !== null && $schema->hasType($typeName) after this would resolve to true then.

I have no idea, why graphql-php does not try again after a full scan (possibly performance issues) or where the exact problem lies here - hence i do not know how to fix it. (maybe api-platform uses / can use a typeLoader in the schema class, maybe something else does need to be specified). Maybe someone here with more insight knows what the problem is.

@soyuka
Copy link
Member

soyuka commented Oct 24, 2024

Mhh indeed this is a hard problem read more at: https://github.com/api-platform/core/blob/main/src/GraphQl/Type/FieldsBuilder.php#L293-L301

If you find a way to fix this in a quick and dirty (opposed to the multi days refactor this comments refer to) manner I'm definitely up for it!

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

No branches or pull requests

2 participants