folkloreinc / laravel-graphql

Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.
1.76k stars 234 forks source link

Change the default resolver w/o the config file? #355

Open edalzell opened 6 years ago

edalzell commented 6 years ago

Is there a way to change the default resolver?

I'm trying to put GraphQL on top of a CMS where the data on an object is retrieved with $object->data('fieldname')

I'd love to set that as the default resolver somehow w/o using the config file (the way I've got it set up those files aren't used).

Alternatively, can I set the resolveField somehow?

jpnut commented 6 years ago

If you take a look inside the main class of this package, you'll see that the default field resolver is set in the queryAndReturnResult method.

https://github.com/Folkloreatelier/laravel-graphql/blob/37e93832c77bdb2a2ec2764066293642c2286357/src/Folklore/GraphQL/GraphQL.php#L160-L176

I don't immediately see an easy way to extend this function and implement a custom default field resolver, but at worst you could simply copy the function definition and re-define the field resolver variable. Note that you'll need to register your own service provider (and, as a result, prevent the package from being autoloaded) and reference the extended version of this file which contains the overridden function. Hope that helps!