feat: support custom fieldResolver in createSchemaForApollo #2327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Because of the way how
createSchemaForApollo
works if you want to override Apollo Server's default field resolvers you can't do so in Apollo Schema optionsFixes (issue)
Type of change
Screenshots/Sandbox (if appropriate/relevant):
How Has This Been Tested?
My use case is very simple: a legacy application that mixes database entities managed directly by the ORM with GraphQL helpers that aim to reduce the load down the graph. Whenever makes sense to return these helpers the return type is an object/array with the entity and the helpers, otherwise it's just the Entity. The custom fieldResolver function looks at the type: if it's an entity it returns the default fieldResolver function, otherwise it looks for the fieldName in the
info
object and decides if to call the default fieldResolver function on the entity or on the helpers.That's just a simple
fieldResolver
function to test if it works properly.Test Environment:
graphql-modules
: 2.1.1Checklist:
Further comments
I didn't create any tests nor updated the documentation. If you think this is something worth adding to createSchemaForApollo I will do so before we merge this.
At this point we might just expose as well
typeResolver
andsubscribeFieldResolver
.