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 Nested Children error ( is used outside the scope of its declaration ) #5007

Closed
develth opened this issue Sep 23, 2022 · 14 comments
Closed

Comments

@develth
Copy link
Contributor

develth commented Sep 23, 2022

API Platform version(s) affected: 3.0

Description
When query an item that have an nested set ( what i solved with Doctrine Extensions Nested Set ) and want to make query with children, following error appears:

[Semantical Error] line 0, col 89 near 'o_a6.id = m_a7.deletedBy': Error: 'o_a6' is used outside the scope of its declaration.

The Request via REST is sucessful.
Debuggin braught me LinksHandlerTrait, that wants to make sub query to fields that have a manyToOne relation on this object.

How to reproduce

  • DoctrineExtension with a NestedSet
  • Query an Item with Children and that have a manyToOne relation to another Object

Additional Context

GraphQL Query:

query listTreeItemsQuery($treeItem: ID!) {
  treeItem(id: $treeItem) {
          id
          name
          children{
              totalCount
          }
        
  }
}
@develth
Copy link
Contributor Author

develth commented Sep 23, 2022

Further Information:
It tries to add the failing fields that are outside the scope in following line:

There it seems, that $link->getFromClass() and $previousAlias are the same and does not point to the referenced relation

@phtmgt
Copy link

phtmgt commented Sep 28, 2022

Same here in 2.7. It looks like 2.7 and 3.0 have so many issues with graphql that I don't think they are proper releases. I battled with 3.0 for more than a day, then went back to 2.7 and despite the small progress (now it at least returns responses in less than 300 seconds), the issues keep popping. There are some forks that supposedly 'fix' graphql issues, but they only take you that far. GraphQL keeps looking more and more like an afterthought with api-platform. And let's be real here, creating a serious API with REST is so 2000s it's not even funny.

@huelsmc
Copy link

huelsmc commented Sep 29, 2022

Did someone saw a solution (in a fork) for this specific issue mentioned here?

@webda2l
Copy link
Contributor

webda2l commented Sep 29, 2022

Did someone saw a solution (in a fork) for this specific issue mentioned here?

Give a try to #5001 (comment), It solved a similar case and I don't have any issues currently.
Then you're welcome to add tests to my pending PRs :)

@phtmgt
Copy link

phtmgt commented Sep 29, 2022

Sorry, I gave up and went back to 2.6.x. Good luck.

@tsdevelopment
Copy link

@alanpoulain will there be a fix for that in the near future?

@alanpoulain
Copy link
Member

The fix is probably here, I need to take some time to review it: #5169.

@develth
Copy link
Contributor Author

develth commented Nov 17, 2022

no really, because currently i get:

 "debugMessage": "More than one result was found for query although one row or none was expected.",

It wants to use the ItemProvider for the child collection

@develth
Copy link
Contributor Author

develth commented Nov 17, 2022

IMHO its caused by this @alanpoulain

https://github.com/api-platform/core/blob/v3.0.4/src/GraphQl/Type/FieldsBuilder.php#L265

especially:

$rootOperation->getClass() !== $resourceClass

With Children, both are same and it will decide everytime for ItemProvider instead of Collection

@alanpoulain
Copy link
Member

The issue is more like, why this line gives you false, isn't it?

$isCollectionType = $this->typeBuilder->isCollection($type);

@develth
Copy link
Contributor Author

develth commented Nov 17, 2022

The issue is more like, why this line gives you false, isn't it?

it is true

That is why it gets here

 $resourceClass = $collectionValueType->getClassName();

and gehts the Class of the Model, what is the same as the parent and does think its also needed for the ItemProvider

@alanpoulain
Copy link
Member

OK it's because the root class is the same as the child class.
Maybe it needs a check on the depth instead.

@develth
Copy link
Contributor Author

develth commented Nov 17, 2022

or just use the collectionCheck here, too?

@NicoHaase
Copy link
Contributor

NicoHaase commented Jan 6, 2023

Are there any news on this topic? I'd like to update my application to ApiPlatform v3, but this bug blocks this update. Do you need any additional information to reproduce the problem? The fix in #5169 does not work for me

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

7 participants