how exactly root parameter used in sangria? here is documentation
preparedQuery.execute(userContext = someCustomCtx, root = event))
query already contains resolver, how than root would be used?
how exactly root parameter used in sangria? here is documentation
preparedQuery.execute(userContext = someCustomCtx, root = event))
query already contains resolver, how than root would be used?
Copyright © 2021 Jogjafile Inc.
Graphqlqueries are nested in nature, meaning that everyGraphQLquery has the shape of a tree, they are never circular.The execution begins at the root of the query. First, the executor calls the resolve function of the fields at the top level. It waits until all these resolve functions have returned a value. As soon as that happens, the GraphQL server will take the return value of this resolve function and pass it to the resolve functions of the second level fields because those are the fields that were requested in the query.
Results from one node of the tree are available to all its immediate children, this continues in a cascading fashion down the tree.
Meanwhile,
Contextis an object shared by all resolvers in a particular query, and is used to contain per-request state, including authentication information, dataloader instances, and anything else that should be taken into account when resolving the query.Contextis different fromRootin that it is computed first and then is available for all the fields.Now with all this context, to answer your question, the resolvers for the top level fields have the root value available for them. This
rootvaluetypeis defined in the executor itself-case class Executor[Ctx, Root]and you pass an instance of
Roottype(or any other instance that can be proved to be as same as thistype) when you call theexecutefunction.If your use case requires no use of this
Root, you can set it as Unit and pass inroot = (),when invoking the execute method.