graphql / graphql/graphql-spec

Redundant field aliases identical to field names

Open
#1,035 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

This is something that's been on my mind for a while, and I reckon, the easiest way for me to forget about it and clarify this little quirk would make me finally forget about it.

The relevant part of the grammar are
> Alias :
> Name `:`
> Field
> Alias(opt) Name Arguments(opt) Directives(opt) SelectionSet(opt)

Hence, it's legal to write `field: field`, i.e. define an alias that matches the field's name but is redundant.

In the reference implementation this currently of course parses as a valid alias with the value `"field"` and a name `"field"`. When printed, this is preserved as `field: field` as well.

In other words, it's only implied that an alias identical to a field name is redundant and hence I believe it may be beneficial to add a non-normative note stating this to be the case.

Stating that the alias can be discarded if it's equal to the field name may obviously have negative ramifications when anyone relies on how the reference implementation prints GraphQL documents (although, arguably, the spec currently also doesn't state how normalised this representation should be, so maybe it's unnecessary to worry about this)

However, imho, it might be beneficial to clarify in such a non-normative note — either near [`CollectFields`](https://spec.graphql.org/draft/#sel-LANRPLCFFFFBBABF2tZ) or [`Field Alias`](https://spec.graphql.org/October2021/#sec-Field-Alias) — that it's always redundant when executing a GraphQL operation.

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.