From 1df1ba5892cc486d480951b411794b2996492314 Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Thu, 13 Feb 2025 09:51:34 -0800 Subject: [PATCH 1/6] Add validation for duplicate lookups. Duplicate lookup fields creates ambiguity for the query planner --- spec/Section 2 -- Source Schema.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index 44759a7..c791836 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -136,6 +136,23 @@ type Product @key(fields: "id") { } ``` +For a given subgraph, there must be only one lookup field that can resolve a given +entity by a specific key. If multiple lookup fields are defined that resolve the +same entity by the same key, the composition process must throw a composition +error. + +```graphql counter-example +type Query { + product(id: ID!): Product @lookup + productV2(id: ID!): Product @lookup +} + +type Product @key(fields: "id") @key(fields: "sku") { + id: ID! + sku: String! +} +``` + Lookups can also be nested within other lookups and allow resolving nested entities that are part of an aggregate. In the following example the `Product` can be resolved by its ID but also the `ProductPrice` can be resolved by passing From 01aa718c385b3400755c2596aef3dfbeae6d3a3c Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Thu, 13 Feb 2025 09:57:14 -0800 Subject: [PATCH 2/6] Simplify example --- spec/Section 2 -- Source Schema.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index c791836..7147f45 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -147,7 +147,7 @@ type Query { productV2(id: ID!): Product @lookup } -type Product @key(fields: "id") @key(fields: "sku") { +type Product @key(fields: "id") { id: ID! sku: String! } From 27d6504ea783b22c3f742c2a4e4a3d489dd7ccb5 Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Sun, 16 Feb 2025 17:10:05 -0800 Subject: [PATCH 3/6] Update spec/Section 2 -- Source Schema.md Co-authored-by: Glen --- spec/Section 2 -- Source Schema.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index 7147f45..97fe060 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -136,7 +136,7 @@ type Product @key(fields: "id") { } ``` -For a given subgraph, there must be only one lookup field that can resolve a given +For a given source schema, there must be only one lookup field that can resolve a given entity by a specific key. If multiple lookup fields are defined that resolve the same entity by the same key, the composition process must throw a composition error. From e5c04e5b4205b5f556fa03f8cdd0db7ef4cf7dda Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Sun, 16 Feb 2025 17:14:12 -0800 Subject: [PATCH 4/6] Prettier --- spec/Section 2 -- Source Schema.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index 97fe060..728be8b 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -136,10 +136,10 @@ type Product @key(fields: "id") { } ``` -For a given source schema, there must be only one lookup field that can resolve a given -entity by a specific key. If multiple lookup fields are defined that resolve the -same entity by the same key, the composition process must throw a composition -error. +For a given source schema, there must be only one lookup field that can resolve +a given entity by a specific key. If multiple lookup fields are defined that +resolve the same entity by the same key, the composition process must throw a +composition error. ```graphql counter-example type Query { From 973d66d34956658aa7a27c501f3444414ff96a50 Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Mon, 17 Feb 2025 11:32:34 -0800 Subject: [PATCH 5/6] Update Section 2 -- Source Schema.md --- spec/Section 2 -- Source Schema.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index 728be8b..1a24507 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -136,8 +136,8 @@ type Product @key(fields: "id") { } ``` -For a given source schema, there must be only one lookup field that can resolve -a given entity by a specific key. If multiple lookup fields are defined that +For a given source schema, there must be exactly one non-deprecated lookup field that can resolve +a given entity by a specific key. If multiple non-deprecated lookup fields are defined that resolve the same entity by the same key, the composition process must throw a composition error. From 88b6525a49d278fabe0b86c23fb2f8f9aeb8eb40 Mon Sep 17 00:00:00 2001 From: Stephen Spalding Date: Mon, 17 Feb 2025 11:41:28 -0800 Subject: [PATCH 6/6] Prettier --- spec/Section 2 -- Source Schema.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/Section 2 -- Source Schema.md b/spec/Section 2 -- Source Schema.md index 1a24507..bbae97c 100644 --- a/spec/Section 2 -- Source Schema.md +++ b/spec/Section 2 -- Source Schema.md @@ -136,10 +136,10 @@ type Product @key(fields: "id") { } ``` -For a given source schema, there must be exactly one non-deprecated lookup field that can resolve -a given entity by a specific key. If multiple non-deprecated lookup fields are defined that -resolve the same entity by the same key, the composition process must throw a -composition error. +For a given source schema, there must be exactly one non-deprecated lookup field +that can resolve a given entity by a specific key. If multiple non-deprecated +lookup fields are defined that resolve the same entity by the same key, the +composition process must throw a composition error. ```graphql counter-example type Query {