You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -138,9 +137,6 @@ The `set-graphql-resolver` policy retrieves or sets data for a GraphQL field in
138
137
139
138
* This policy is invoked only when a matching GraphQL query is executed.
140
139
* The policy resolves data for a single field. To resolve data for multiple fields, configure multiple occurrences of this policy in a policy definition.
141
-
* The context for the HTTP request and HTTP response (if specified) differs from the context for the original gateway API request:
142
-
* The HTTP request context contains arguments that are passed in the GraphQL query as its body.
143
-
* The HTTP response context is the response from the independent HTTP call made by the resolver, not the context for the complete response for the gateway request.
|`http-data-source`| Configures the HTTP request and optionally the HTTP response that are used to resolve data for the given `parent-type` and `field`. | Yes |
171
+
|`http-request`| Specifies a URL and child policies to configure the resolver's HTTP request. Each child element can be specified at most once. | Yes |
172
+
|`set-method`| Method of the resolver's HTTP request, configured using the [set-method](api-management-advanced-policies.md#SetRequestMethod) policy. | Yes |
173
+
|`set-url`| URL of the resolver's HTTP request. | Yes |
174
+
|`set-header`| Header set in the resolver's HTTP request, configured using the [set-header](api-management-transformation-policies.md#SetHTTPheader) policy. | No |
175
+
|`set-body`| Body set in the resolver's HTTP request, configured using the [set-body](api-management-transformation-policies.md#SetBody) policy. | No |
176
+
|`authentication-certificate`| Client certificate presented in the resolver's HTTP request, configured using the [authentication-certificate](api-management-authentication-policies.md#ClientCertificate) policy. | No |
177
+
|`http-response`| Optionally specifies child policies to configure the resolver's HTTP response. If not specified, the response is returned as a raw string. Each child element can be specified at most once. |
178
+
|`json-to-xml`| Transforms the resolver's HTTP response using the [json-to-xml](api-management-transformation-policies.md#ConvertJSONtoXML) policy. | No |
179
+
|`xml-to-json`| Transforms the resolver's HTTP response using the [xml-to-json](api-management-transformation-policies.md#ConvertJSONtoXML) policy. | No |
180
+
|`find-and-replace`| Transforms the resolver's HTTP response using the [find-and-replace](api-management-transformation-policies.md#Findandreplacestringinbody) policy. | No |
|`parent-type`| An object type in the GraphQL schema. | Yes | N/A |
188
+
|`field`| A field of the specified `parent-type` in the GraphQL schema. | Yes | N/A |
189
+
190
+
> [!NOTE]
191
+
> Currently, the values of `parent-type` and `field` aren't validated by this policy. If they aren't valid, the policy is ignored, and the GraphQL query is forwarded to a GraphQL endpoint (if one is configured).
192
+
193
+
### Usage
194
+
195
+
This policy can be used in the following policy [sections](./api-management-howto-policies.md#sections) and [scopes](./api-management-howto-policies.md#scopes).
196
+
197
+
-**Policy sections:** backend
198
+
-**Policy scopes:** all scopes
199
+
200
+
### GraphQL Context
201
+
202
+
* The context for the HTTP request and HTTP response (if specified) differs from the context for the original gateway API request:
203
+
*`context.ParentResult` is set to the parent object for the current resolver execution.
204
+
* The HTTP request context contains arguments that are passed in the GraphQL query as its body.
205
+
* The HTTP response context is the response from the independent HTTP call made by the resolver, not the context for the complete response for the gateway request.
206
+
The `context` variable that is passed through the request and response pipeline is augmented with the GraphQL context when used with `<set-graphql-resolver>` policies.
207
+
208
+
#### ParentResult
209
+
210
+
The `context.ParentResult` is set to the parent object for the current resolver execution. Consider the following partial schema:
If you set a resolver for `parent-type="Blog" field="comments"`, you will want to understand which blog ID to use. You can get the ID of the blog using `context.ParentResult.AsJObject()["id"].ToString()`. The policy for configuring this resolver would resemble:
### Resolver for a GraqhQL query that returns a list, using a liquid template
344
+
####Resolver for a GraqhQL query that returns a list, using a liquid template
202
345
203
-
The following example uses a liquid template, supported for use in the [set-body](api-management-transformation-policies.md#SetBody) policy, to return a list in the HTTP response to a query.
346
+
The following example uses a liquid template, supported for use in the [set-body](api-management-transformation-policies.md#SetBody) policy, to return a list in the HTTP response to a query. It also renames the `username` field in the response from the REST API to `name` in the GraphQL response.
The following example resolves a mutation that inserts data by making a `POST` request to an HTTP data source. The policy expression in the `set-body` policy of the HTTP request modifies a `name` argument that is passed in the GraphQL query as its body.
387
+
The following example resolves a mutation that inserts data by making a `POST` request to an HTTP data source. The policy expression in the `set-body` policy of the HTTP request modifies a `name` argument that is passed in the GraphQL query as its body. The body that is sent will look like the following JSON:
|`http-data-source`| Configures the HTTP request and optionally the HTTP response that are used to resolve data for the given `parent-type` and `field`. | Yes |
291
-
|`http-request`| Specifies a URL and child policies to configure the resolver's HTTP request. Each child element can be specified at most once. | Yes |
292
-
|`set-method`| Method of the resolver's HTTP request, configured using the [set-method](api-management-advanced-policies.md#SetRequestMethod) policy. | Yes |
293
-
|`set-url`| URL of the resolver's HTTP request. | Yes |
294
-
|`set-header`| Header set in the resolver's HTTP request, configured using the [set-header](api-management-transformation-policies.md#SetHTTPheader) policy. | No |
295
-
|`set-body`| Body set in the resolver's HTTP request, configured using the [set-body](api-management-transformation-policies.md#SetBody) policy. | No |
296
-
|`authentication-certificate`| Client certificate presented in the resolver's HTTP request, configured using the [authentication-certificate](api-management-authentication-policies.md#ClientCertificate) policy. | No |
297
-
|`http-response`| Optionally specifies child policies to configure the resolver's HTTP response. If not specified, the response is returned as a raw string. Each child element can be specified at most once. |
298
-
|`json-to-xml`| Transforms the resolver's HTTP response using the [json-to-xml](api-management-transformation-policies.md#ConvertJSONtoXML) policy. | No |
299
-
|`xml-to-json`| Transforms the resolver's HTTP response using the [xml-to-json](api-management-transformation-policies.md#ConvertJSONtoXML) policy. | No |
300
-
|`find-and-replace`| Transforms the resolver's HTTP response using the [find-and-replace](api-management-transformation-policies.md#Findandreplacestringinbody) policy. | No |
|`parent-type`| An object type in the GraphQL schema. | Yes | N/A |
308
-
|`field`| A field of the specified `parent-type` in the GraphQL schema. | Yes | N/A |
309
-
310
-
> [!NOTE]
311
-
> Currently, the values of `parent-type` and `field` aren't validated by this policy. If they aren't valid, the policy is ignored, and the GraphQL query is forwarded to a GraphQL endpoint (if one is configured).
312
-
313
-
### Usage
314
-
315
-
This policy can be used in the following policy [sections](./api-management-howto-policies.md#sections) and [scopes](./api-management-howto-policies.md#scopes).
0 commit comments