Closed AljosaB closed 1 year ago
Hi, any update on this. I am also facing same issue when upgrading from v3 to v4
Replicated the issue. One important point here is that the thing would work fine if PageExtendingSomePage
didn't extend SomePage
.
So it looks like graphql, when building its schema, probably tries to instantiate every single parent in the class hierarchy. There's probably a point where it should be directly instantiating a class but it uses the Injector instead. Something like this is probably happening somewhere:
function getDefinitionForClass(string $classname)
{
$singleton = Injector::get()->create($classname);
$definition = $singleton->getMyClassDefinition();
$parentClass = $singleton->getParentClassName()
$this->getDefinitionForClass($parentClass); // This will be called with `SomePage` which Injector will convert back to `PageExtendingSomePage` for infinity
}
My gut feeling is that this should be a legitimate use case that we should support.
I've edited the original post and the comments to make it more obvious that it's about using Injector to replace a class that is an ancestor of the new class. Also SomePageExtension
name indicated it could be a data extension applied to a page class which it wasn't.
I've patched this on my fork (comMit above) however pretty sure this is not the best method and needs a unit test for me to be happier. Happy to submit a PR if above looks OK or I'm open to other suggestions.
@wilr thanks for the fix - I've created a PR and put you down as co-author on the commit - https://github.com/silverstripe/silverstripe-graphql/pull/549
PR merged. It will be automatically tagged by GitHub Actions.
Affected Version
SS 4.11+ GrapQl v4
Steps to Reproduce
/app/src/SomePage.php
/app/src/PageExtendingSomePage.php
/app/_config/injectors.yml
/app/_config/graphql.yml
/app/_graphql/models.yml
Run
Error
Additional info
Acceptance criteria
PRs