Problem/Motivation
We've got the AST for the base schema and the extensions cached. The other thing we need to serve GraphQL requests is the Resolver Registry, since it informs us what to call for each field.
90% of the Resolver Registry are static references to classes which can easily be serialized and cached. However, the existence of the Callback resolver means that the serialization of the Registry may be prevented and break.
Although using callbacks can be easy to prototype, there's nothing that they can do that a proper data producer class can not do and besides quick prototyping the maintenance is often worse.
If we can get the resolver registry cacheable then I believe we can boot up the GraphQL server without loading any plugins (we would only need the schema AST and the serialized registry).
Steps to reproduce
Proposed resolution
Deprecate the callback resolver (the class itself and ResolverBuilder::callback) for removal in GraphQL 6.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork graphql-3576071
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
kingdutchCode is ready for review. Leaving assigned to Klausi to get buy-in on the plan :)
As a follow-up we may also need to address
ResolverBuilder::fromContextwhich currently requests acallableto pass toContextbut that callable is never actually invoked, the Context class expects static default values.Comment #4
klausiThanks, I think I'm ok with this. At Jobiqo we use too many callback resolvers, so this will be a bit painful to upgrade for us.
But in general I agree, I also prefer to see dataproducer code in actual dataproducer classes.
Can you fix the phpstan errors? I think we need to update examples and docs by removing all callback stuff there.
Comment #5
kingdutchComment #6
kingdutchUpdated the docs and fixed PHPStan. Relying on the review from #4 to be able to tag beta3.
Comment #9
klausiOne thing I noticed here is that all example dataproducers should be prefixed with the module name - that is a best practice to avoid name clashes.
Can be fixed in a follow-up.
Comment #12
pfrenssenI want to share an AI skill I have made to facilitate the conversion from callback to data producer. We had to migrate a TON of callbacks and I noticed during the work that there are several types of callbacks which can match to different patterns. I have distilled this into a detailed skill which takes away most of the repetitive work.
As always, AI skills are opinionated (e.g. the use of DDEV is assumed, and a preference for ExistingSite over KernelTest is mentioned), but it has been serving us well and I hope it will help out others.