New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds field selection RFC #35
base: main
Are you sure you want to change the base?
Conversation
From the meeting on May 2, @benjie has a comparable solution defined that builds on top of the schema coordinates proposal In short, this pathing operator https://github.com/graphql/graphql-wg/blob/main/rfcs/OperationExpressions.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've included some comments below, but I like the direction of the last solution.
To my mind the system knows if the input is a scalar or not. If it's a scalar, we expect a "single field" expression. If it's an input object, we expect a "multi field" expression (key1: expression1 key2: expression2
); and for each of these expressions we apply the same heuristics: if it's a scalar, a single field expression, if an input object then a multi field expression wrapped in {}
to avoid ambiguity.
My main concern is that the "expression" should use GraphQL syntax to explicitly select a single value. It's not terrible that this is implied via selection sets and the system knowing to traverse, but it would be better if this just "fell out" of the GraphQL syntax automatically, so I'm keen to see if exploring the flat chain syntax would get us any closer.
This introduces additional complexity as the input object requires reshaping. The input fields | ||
`UserInput.info.firstName` and `UserInput.name` correspond to the fields `User.firstName` and | ||
`User.name`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively you could use an operation expression such as >findUserByName(user>info>firstName:)
, e.g.
This introduces additional complexity as the input object requires reshaping. The input fields
>findUserByName(user>info>firstName:)
and>findUserByName(user>name:)
correspond to the fieldsUser.firstName
andUser.name
.
|
||
```graphql | ||
extend type Query { | ||
mediaById(id: ID! @is(field: "<Movie>.id | <Book>.id")): MovieOrBook @lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With operation expressions this would be:
mediaById(id: ID! @is(field: "<Movie>.id | <Book>.id")): MovieOrBook @lookup | |
mediaById(id: ID! @is(field: "Movie.id Book.id")): MovieOrBook @lookup |
That would effectively compile out to: ... Movie { id } ... Book { id }
.
**Output field is deeper in the tree with abstract type and fieldname is different** | ||
```graphql | ||
extend type Query { | ||
findUserByName(user: UserInput! @is(field: "firstName: profile<EntraProfile>.name lastName")): User @lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With operation expressions:
findUserByName(user: UserInput! @is(field: "firstName: profile<EntraProfile>.name lastName")): User @lookup | |
findUserByName(user: UserInput! @is(field: "firstName: profile>EntraProfile.name lastName")): User @lookup |
extend type Query { | ||
# Selection: +--------+ +---------+ | ||
# InputField: +---------+ +---------+ | ||
findUserByName(user: UserInput! @is(field: "fristName: givenName lastName: familyName")): User @lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
findUserByName(user: UserInput! @is(field: "fristName: givenName lastName: familyName")): User @lookup | |
findUserByName(user: UserInput! @is(field: "firstName: givenName lastName: familyName")): User @lookup |
# | ||
# Selection: +------------------------------------------------------------------------+ +--------+ | ||
# InputField: +---------+ | ||
findUserByName(user: UserInput! @is(field: "firstName: profile { ... on EntraProfile { name } ... on AdfsProfile { firstName } } lastName")): User @lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's long been open a proposal for flat chain syntax and I think Lee even mentioned he'd be interested in seeing this. This feels like a compelling use-case to get such a syntax adopted into the spec. Handling polymorphism is something that that particular RFC doesn't address AFAIK. Perhaps a .
would be enough:
findUserByName(user: UserInput! @is(field: "firstName: profile { ... on EntraProfile { name } ... on AdfsProfile { firstName } } lastName")): User @lookup | |
findUserByName(user: UserInput! @is(field: "firstName: profile.{ ... on EntraProfile { name } ... on AdfsProfile { firstName } } lastName")): User @lookup |
This would also improve the previous example:
- findUserByName(user: UserInput! @is(field: "firstName: profile { firstName } lastName")): User @lookup
+ findUserByName(user: UserInput! @is(field: "firstName: profile.firstName lastName")): User @lookup
No description provided.