@@ -11,11 +11,36 @@ passes it to every `getField` method as the first parameter.
1111
1212The ` graphql::service::FieldParams ` struct is declared in [ GraphQLService.h] ( ../include/graphqlservice/GraphQLService.h ) :
1313``` cpp
14- // Pass a common bundle of parameters to all of the generated Object::getField accessors in a SelectionSet
14+ // Resolvers may be called in multiple different Operation contexts.
15+ enum class ResolverContext
16+ {
17+ // Resolving a Query operation.
18+ Query,
19+
20+ // Resolving a Mutation operation.
21+ Mutation,
22+
23+ // Adding a Subscription. If you need to prepare to send events for this Subsciption
24+ // (e.g. registering an event sink of your own), this is a chance to do that.
25+ NotifySubscribe,
26+
27+ // Resolving a Subscription event.
28+ Subscription,
29+
30+ // Removing a Subscription. If there are no more Subscriptions registered this is an
31+ // opportunity to release resources which are no longer needed.
32+ NotifyUnsubscribe,
33+ };
34+
35+ // Pass a common bundle of parameters to all of the generated Object::getField accessors in a
36+ // SelectionSet
1537struct SelectionSetParams
1638{
39+ // Context for this selection set.
40+ const ResolverContext resolverContext;
41+
1742 // The lifetime of each of these borrowed references is guaranteed until the future returned
18- // by the accessor is resolved or destroyed. They are owned by the OperationData shared pointer.
43+ // by the accessor is resolved or destroyed. They are owned by the OperationData shared pointer.
1944 const std::shared_ptr<RequestState>& state;
2045 const response::Value& operationDirectives;
2146 const response::Value& fragmentDefinitionDirectives;
@@ -25,19 +50,32 @@ struct SelectionSetParams
2550 // you'll need to explicitly copy them into other instances of response::Value.
2651 const response::Value& fragmentSpreadDirectives;
2752 const response::Value& inlineFragmentDirectives;
53+
54+ // Field error path to this selection set.
55+ std::optional<field_path> errorPath;
56+
57+ // Async launch policy for sub-field resolvers.
58+ const std::launch launch = std::launch::deferred;
2859};
2960
3061// Pass a common bundle of parameters to all of the generated Object::getField accessors.
3162struct FieldParams : SelectionSetParams
3263{
33- explicit FieldParams(const SelectionSetParams& selectionSetParams, response::Value&& directives);
64+ GRAPHQLSERVICE_EXPORT explicit FieldParams(
65+ SelectionSetParams&& selectionSetParams, response::Value&& directives);
3466
35- // Each field owns its own field-specific directives. Once the accessor returns it will be destroyed,
36- // but you can move it into another instance of response::Value to keep it alive longer.
67+ // Each field owns its own field-specific directives. Once the accessor returns it will be
68+ // destroyed, but you can move it into another instance of response::Value to keep it alive
69+ // longer.
3770 response::Value fieldDirectives;
3871};
3972```
4073
74+ ### Resolver Context
75+
76+ The ` SelectionSetParams::resolverContext ` enum member informs the ` getField `
77+ accessors about what type of operation is being resolved.
78+
4179### Request State
4280
4381The ` SelectionSetParams::state ` member is a reference to the
@@ -75,7 +113,29 @@ or `fragmentDefinitionDirectives` because those are kept alive until the
75113passed by ` const ` reference, the reference should always be valid as long as
76114there's a pending result from the ` getField ` call.
77115
116+ ### Error Path
117+
118+ The ` SelectionSetParams::errorPath ` member should be considered an opaque
119+ implementation detail by client code. It automatically propagates through the
120+ field resolvers, and if there is a schema exception or one of the ` getField `
121+ accessors throws another exception derived from ` std::exception ` , the
122+ ` graphqlservice ` library will automatically add the resulting path to the error
123+ report, accoring to the [ spec] ( http://spec.graphql.org/June2018/#sec-Errors ) .
124+
125+ ### Launch Policy
126+
127+ The ` graphqlservice ` library uses the ` SelectionSetParams::launch ` parameter to
128+ determine how it should handle async resolvers in the same selection set or
129+ elements in the same list. It is passed from the top-most ` resolve ` , ` deliver ` ,
130+ or async ` subscribe ` /` unsubscribe ` call. The ` getField ` accessors get a copy of
131+ this member in their ` FieldParams ` argument, and they may change their own
132+ behavior based on that, but they cannot alter the launch policy which
133+ ` graphqlservice ` uses for the resolvers themselves.
134+
78135## Related Documents
79136
801371 . The ` getField ` methods are discussed in more detail in [ resolvers.md] ( ./resolvers.md ) .
81- 2 . Built-in and custom ` directives ` are discussed in [ directives.md] ( ./directives.md ) .
138+ 2 . Built-in and custom ` directives ` are discussed in [ directives.md] ( ./directives.md ) .
139+ 3 . Subscription resolvers get called up to 3 times depending on which
140+ ` subscribe ` /` unsubscribe ` overrides you call. See [ subscriptions.md] ( ./subscriptions.md )
141+ for more details.
0 commit comments