Enable passing values configuration to GraphQLEnumType as a thunk #4018
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.
Many of the type configuration objects in GraphQL-js have properties that accept thunks:
These are because their definitions may contain references to other types which may form cycles, and thus a thunk is required to enable their definition.
This PR allows setting
GraphQLEnumTypeConfig.values
to be a thunk. At first, this might seem unnecessary (and, well, it has been this way for 9 years so you can be forgiven for thinking that) but it can be quite useful when building enums that reference types. For example: you might have a field that returns a union (Person.pets
), and you might want to add an argument that allows you to limit the returned types to only certain types (Person.pets(only:)
):For this it can be useful for the
AnimalType
type to enumerate the types in theAnimal
union, but those types contain references back toAnimalType
-> there's a cycle.The thunk approach outlined in this PR would solve the cycle. There are workarounds (i.e. manually listing out the types) but they're not as ergonomic as (and are more error-prone than) resolving the values directly from the union.