graphql / graphql/graphql-spec

[RFC] Flat chain syntax

Open
#174 32 comments 167 reactions 0 assignees View on GitHub
👻 Needs Champion 💭 Strawman (RFC 0)
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Often times we want to fetch just a single field from a nested relation. e.g.

```
{
clients(limit: 5) {
id
programs {
shortName
}
}
}
```

It would be nice if there was a syntax to allow getting back a flat array of program shortNames instead of an array of objects. e.g.

```
{
clients(limit: 5) {
id
programs: programs.shortName
}
}
```

This would return something like:

```
{
"data": {
"clients": [
{
"id": 2,
"programs": ["ABC","DEF"]
},
{
"id": 3,
"programs": ["ABC", "XYZ"]
]
}
]
}
}
```

Giving it an alias could either be mandatory, or it could default to using the outer field name (default to "programs", "shortName" would be discarded).

A library like GraphQL-JS could handle the normalization of array-of-objects to flat-array-of-strings automatically, so there wouldn't be any additional work for someone implementing a schema.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.