Skip to content

Commit

Permalink
feat(configuration): Add docs for select field on HTTP and gRPC direc…
Browse files Browse the repository at this point in the history
…tives (#527)
  • Loading branch information
karatakis authored Oct 9, 2024
1 parent a357eda commit 6c3314a
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,37 @@ type Query {
}
```

### select

You can use `select` with mustache syntax to re-construct the directives
response to the desired format. This is useful when data are deeply
nested or want to keep specific fields only from the response.

- EXAMPLE 1: if we have a call that returns `{ "user": { "items": [...],
... } ... }` we can use `"{{.user.items}}"`, to extract the `items`.
- EXAMPLE 2: if we have a call that returns `{ "foo": "bar", "fizz": {
"buzz": "eggs", ... }, ... }` we can use `{ foo: "{{.foo}}", buzz:
"{{.fizz.buzz}}" }`

```graphql showLineNumbers
type Query {
userCompany(id: Int!): Company
@grpc(
method: "news.UsersService.GetUserDetails"
select: "{{.company}}"
)
userDetails(id: Int!): UserDetails
@grpc(
method: "news.UsersService.GetUserDetails"
select: {
id: "{{.id}}"
city: "{{.address.city}}"
phone: "{{.phone}}"
}
)
}
```

## @http Directive

The `@http` directive indicates a field or node relies on a REST API. For example:
Expand Down Expand Up @@ -1034,6 +1065,37 @@ type Query {
}
```

### select

You can use `select` with mustache syntax to re-construct the directives
response to the desired format. This is useful when data are deeply
nested or want to keep specific fields only from the response.

- EXAMPLE 1: if we have a call that returns `{ "user": { "items": [...],
... } ... }` we can use `"{{.user.items}}"`, to extract the `items`.
- EXAMPLE 2: if we have a call that returns `{ "foo": "bar", "fizz": {
"buzz": "eggs", ... }, ... }` we can use `{ foo: "{{.foo}}", buzz:
"{{.fizz.buzz}}" }`

```graphql showLineNumbers
type Query {
userCompany(id: Int!): Company
@http(
path: "/users/{{.args.id}}"
select: "{{.company}}"
)
userDetails(id: Int!): UserDetails
@http(
path: "/users/{{.args.id}}"
select: {
id: "{{.id}}"
city: "{{.address.city}}"
phone: "{{.phone}}"
}
)
}
```

## @js Directive

The `@js` directive allows you to use JavaScript functions to resolve fields in your GraphQL schema. This can be useful
Expand Down

0 comments on commit 6c3314a

Please sign in to comment.