GraphQL types/fields concept is quite recursive. The usually called RootQuery
is as much a custom type as any other type in your schema. Usually, though, this RootQuery
type contains only dynamically resolved fields, but this is no limitation. If you want people to access a string scalar name
field on a User
type you don't need to write a resolver function for it, as long as the object resolved to any User
returning field contains that name
property; this works just the same way with the RootValue
, but that object will be the object provided via rootValue
.
Context, in the other hand, is something that will be made available to every resolver, but will never be queriable by any user sending queries against the GraphQL server - thus making context the perfect place for keeping sensitive data, such as session information.
Sample:
here goes a sample usage of rootValue: https://runkit.com/lucasconstantino/graphql-root-value-sample