Skip to content

Commit 4e405e6

Browse files
committed
Updated from jihoon
1 parent 43dc1ed commit 4e405e6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

articles/api-management/graphql-policies.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ type User {
343343

344344
### Resolver for a GraqhQL query that returns a list, using a liquid template
345345

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.
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.
347347

348348
#### Example schema
349349

@@ -372,7 +372,7 @@ type User {
372372
[
373373
{% JSONArrayFor elem in body %}
374374
{
375-
"name": "{{elem.title}}"
375+
"name": "{{elem.username}}"
376376
}
377377
{% endJSONArrayFor %}
378378
]
@@ -384,7 +384,13 @@ type User {
384384

385385
### Resolver for GraphQL mutation
386386

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.
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:
388+
389+
``` json
390+
{
391+
"name": "the-provided-name"
392+
}
393+
```
388394

389395
#### Example schema
390396

@@ -415,9 +421,9 @@ type User {
415421
<value>application/json</value>
416422
</set-header>
417423
<set-body>@{
418-
var body = context.Request.Body.As<JObject>(true);
424+
var args = context.Request.Body.As<JObject>(true)["arguments"];
419425
JObject jsonObject = new JObject();
420-
jsonObject.Add("name", body["name"])
426+
jsonObject.Add("name", args["name"])
421427
return jsonObject.ToString();
422428
}</set-body>
423429
</http-request>

0 commit comments

Comments
 (0)