Envelop v2 documentation (superseded by v4): Using GraphQL Features from the Future
Envelop allows to hook into and extend all phases of the GraphQL execution pipeline. Because of that
envelop can be used to implement features that are not yet available in the GraphQL.js core and are
only proposed as RFC candidates.
OneOf Input Objects and OneOf Fields
Unions and Interfaces are essential primitives for building scalable GraphQL schemas. But they
cannot be used for describing polymorphic input types.
The following is illegal. Only object types can be union members:
Mutations, Subscriptions and Queries can have variable definitions today. For fragments a way of
passing down variables in a capsulated way is impossible. If you use variables in fragments today
they always refer to the global variables object, which limits flexibility.
fragment UserAvatar on User { id avatar(size: $size) { url }}
query UserProfile { me { id ...UserAvatar fiends { id name ...UserAvatar } }}
It is impossible to reuse the UserAvatar with different values for the $size variable.
Fragment arguments allow doing exactly that!
fragment UserAvatar($size: Size!) on User { id avatar(size: $size) { url }}
query UserProfile { me { id ...UserAvatar(size: "large") fiends { id name ...UserAvatar(size: "small") } }}
Frameworks such as relay allow doing similar via directives today. It is time this becomes part of
the GraphQL specification and is officially supported!
Envelop already allows using fragment arguments by extending the GraphQL parser. We don’t recommend
using this for production usage! Please only use it for research or learning purposes!
import { envelop } from '@envelop/core'import { useFragmentArguments } from '@envelop/fragment-arguments'const getEnveloped = envelop({ plugins: [ // ... other plugins ... useFragmentArguments() ]})
This site uses cookies for analytics and improving your experience.