Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

PascalSenn
Copy link

No description provided.

@smyrick
Copy link

smyrick commented May 2, 2024

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 . is replaced with > and then selection is schema coordinates

https://github.com/graphql/graphql-wg/blob/main/rfcs/OperationExpressions.md

Copy link
Member

@benjie benjie left a 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.

Comment on lines +291 to +293
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`.
Copy link
Member

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 fields User.firstName and User.name.


```graphql
extend type Query {
mediaById(id: ID! @is(field: "<Movie>.id | <Book>.id")): MovieOrBook @lookup
Copy link
Member

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:

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With operation expressions:

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo:

Suggested change
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
Copy link
Member

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:

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants