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

Add validation for duplicate lookups. #170

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

Conversation

fotoetienne
Copy link

Duplicate lookup fields creates ambiguity for the query planner

Duplicate lookup fields creates ambiguity for the query planner
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for composite-schemas ready!

Name Link
🔨 Latest commit 88b6525
🔍 Latest deploy log https://app.netlify.com/sites/composite-schemas/deploys/67b3965c8ecdbe00083776e0
😎 Deploy Preview https://deploy-preview-170--composite-schemas.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@andimarek
Copy link

I think in order to allow for migration in a non breaking way we should allow deprecated fields. So it should be two or more non-deprecated lookup fields cause an error.

@fotoetienne
Copy link
Author

I think in order to allow for migration in a non breaking way we should allow deprecated fields. So it should be two or more non-deprecated lookup fields cause an error.

That's a good idea. So the query planner would always choose the non-deprecated one, making it still unambiguous.

@michaelstaib
Copy link
Member

I think in order to allow for migration in a non breaking way we should allow deprecated fields. So it should be two or more non-deprecated lookup fields cause an error.

we could discard of the deprecated lookup in the composition so that the gateway does not need to choose.

@martijnwalraven
Copy link

we could discard of the deprecated lookup in the composition so that the gateway does not need to choose.

But that would break existing clients that depend on the deprecated lookup field. So I don't think we want to remove them completely, just enforce that there's always exactly one non-deprecated lookup for composition and query planning to take advantage of.

@fotoetienne
Copy link
Author

I think in order to allow for migration in a non breaking way we should allow deprecated fields. So it should be two or more non-deprecated lookup fields cause an error.

On further reflection, I believe migration could also be handled in a non-breaking way without allowing multiple @lookups.

before:

type Query {
    bookById(id: ID!): Book @lookup
}

after:

type Query {
    bookById(id: ID!): Book @deprecated
    bookByIdV2(id: ID!): Book @lookup
}

The subgraph would just move @lookup to the new field while leaving the old field present in the schema but without @lookup directive.

Perhaps for simplicity we can indeed restrict to a single @lookup without hindering migration.

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.

5 participants