-
-
Notifications
You must be signed in to change notification settings - Fork 566
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
Interface lazy loading, field definitions as closure not working #38
Comments
In older versions of the lib, even while using callbacks to describe interfaces, it was called when an object implemented this interface. The full explanation of the why is detail in PR #33. But your trouble seems to come from somewhere else, because we use the same implementation with latest lib version without no error. Here's the code with node relay and fragment that works https://github.com/overblog/GraphQLBundle/blob/master/Tests/Functional/Relay/Node/NodeTest.php#L72-L79. Can you provide some PHP example please? |
First of all, there is a new branch which reflects So you could try this branch before applying any fixes. Maybe your case is covered there. If not - we can dig deeper. The problem with new branch though is that it is the first version with breaking changes since the initial release and it requires some changes in app code. I planned to write changelog or migration guide on this, but didn't have a chance to do this yet. In short - there are several breaking changes:
This pretty much reflects breaking changes of Also make sure to check #35 |
Thanks for your responses and for keeping up with the latest changes! I created a test and a fix for that specific issue: I only have one test failing now:
Does that need to fail there or could we remove that check? The interface is injected and through the lazy initialization that I added becomes a valid type... Could also be a valid behavior IMHO or am I missing something? |
FYI I added your test class to april-2016 branch version and it worked fine without any code modifications. So I guess you will just need to update once new version is released (somewhere on week-end). Thanks for investigating this! And we'll use your test to catch regressions if it's ok. |
Great, then I'll just use my fork until the new version is released. Thanks for adding my test to the new branch! |
I tried out the new branch april-2016 and upgraded my codebase. Thanks for the great work, btw!! There are still some issues with the LazyInterfaces. I updated the testcase slightly so that it fails on the new branch now. Without that change the test runs fine. But it seems that right now all types that you want to call through the interface would have to be created in some other place of the Graph. Do you guys think this is solvable? |
I upgraded graphql-relay-php to the new spec-april2016 branch and had the same issues there. Here is an example: If I don't pass the types manually to the schema, the test fails because graphql does not initialize the types properly. |
I see what you mean. That's exactly the reason why When your type is only referenced in schema as interface implementation and is not referenced anywhere else, it remains invisible for GraphQL during validation phase. So one way to make such types reveal themselves for GraphQL is to pass them to Schema explicitly. That's the route that For now I keep this library as close as possible to I will create separate feature request for this. But if you have other ideas on how to make this work better, please let me know. |
Also note that it is not really This is something I want to improve one day, but now there is no on-demand or lazy initialization of types. |
Thanks for the explanations. I guess Too bad that PHP cannot keep the thread alive so that all the types have to be initialized on each request.... |
@ivome - This is exactly the reason why we've chosen to work with appserver.io. http://appserver.io/ 😄 Scott |
I am having some issues with the new lazy loading of interfaces that was implemented:
I have all of my fields defined in callback functions and inside of those callback functions I have a typeRegistry that creates the types on demand. That has the massive advantage that the instances of the types are only created when they are needed.
That worked fine until the latest version when lazy loading of interfaces was introduced. The loading of the interfaces seems to be called on schema creation:
https://github.com/webonyx/graphql-php/blob/master/src/Schema.php#L36
So the types with interfaces are not known at this point in my setup, because the callback functions that create the types did not execute yet.
When the interface is called, I'm getting an error, because the types are not recognized properly.
The following example query:
Results in an error:
If I change the function
getPossibleTypes
to the following, it works again, at least the error is goneThe node is resolved properly but I don't get the fields returned from the fragments. That was also not working with the previous version v0.5.7.
So I'm wondering if there is something else wrong with the InterfaceType, possibly in combination with the definition of the fields in the callback functions. But I feel like creating them on demand would be the most performant way.
What do we need the lazy loading for, if the function
loadImplementationToInterfaces
is called in the Schema constructor?Any ideas how I should fix that?
The text was updated successfully, but these errors were encountered: