Skip to content

[RFC] Flat chain syntax #174

Open
Open
@mnpenner

Description

@mnpenner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    👻 Needs ChampionRFC Needs a champion to progress (See CONTRIBUTING.md)💭 Strawman (RFC 0)RFC Stage 0 (See CONTRIBUTING.md)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions