From 1918b251d10d0c8ef98624d7b2cd71f594a0f19b Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 3 Oct 2024 17:30:52 +0200 Subject: [PATCH 1/4] Adds validation rule `@lookup` must not return a list --- spec/Section 4 -- Composition.md | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 35d3b72..6e0d970 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,6 +14,65 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation +#### `@lookup` must not return a list + +**Error Code** + +LOOKUP_MUST_NOT_RETURN_LIST + +**Formal Specification** + +- Let {fields} be the set of all field definitions annotated with `@lookup` in the schema. +- For each {field} in {fields}: + - Let {type} be the return type of {field}. + - {IsListType(type)} must be false. + +IsListType(type): + +- If {type} is a Non-Null type: + - Let {innerType} be the inner type of {type}. + - Return {IsSingleObjectType(innerType)}. +- Else if {type} is a List type: + - Return true. +- Else: + - Return false. + +**Explanatory Text** + +Fields annotated with the `@lookup` directive are intended to retrieve a single entity based on provided arguments. +To ensure ambiguity in entity resolution, such fields must return a single object and not a list. +This validation rule enforces that any field annotated with `@lookup` must have a return type that is NOT a list. + +For example, the following usage is valid: + +```graphql example +extend type Query { + userById(id: ID!): User @lookup +} + +type User { + id: ID! + name: String +} +``` + +In this example, `userById` returns a `User` object, satisfying the requirement. + +This counter-example demonstrates an invalid usage: + +```graphql counter-example +extend type Query { + usersByRole(role: String!): [User] @lookup +} + +type User { + id: ID! + name: String +} +``` + +Here, `usersByRole` returns a list of `User` objects, which violates the requirement that a `@lookup` field must return a single object. + ### Merge ### Post Merge Validation From 224f9dbb6a8fe6026ab8c792395aac5ee0687c4c Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 3 Oct 2024 17:51:27 +0200 Subject: [PATCH 2/4] apply fix Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 6e0d970..dacd61b 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -40,7 +40,7 @@ IsListType(type): **Explanatory Text** Fields annotated with the `@lookup` directive are intended to retrieve a single entity based on provided arguments. -To ensure ambiguity in entity resolution, such fields must return a single object and not a list. +To avoid ambiguity in entity resolution, such fields must return a single object and not a list. This validation rule enforces that any field annotated with `@lookup` must have a return type that is NOT a list. For example, the following usage is valid: From 16ad1fcb11397fa7ac92d6112878a184e85d4c9f Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 3 Oct 2024 18:51:59 +0200 Subject: [PATCH 3/4] Update Section 4 -- Composition.md --- spec/Section 4 -- Composition.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index dacd61b..1870190 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -62,7 +62,7 @@ This counter-example demonstrates an invalid usage: ```graphql counter-example extend type Query { - usersByRole(role: String!): [User] @lookup + usersByIds(ids: [ID!]!): [User!] @lookup } type User { @@ -71,7 +71,9 @@ type User { } ``` -Here, `usersByRole` returns a list of `User` objects, which violates the requirement that a `@lookup` field must return a single object. +Here, `usersByIds` returns a list of `User` objects, which violates the requirement that a `@lookup` field must return a single object. + +//TODO explain the `@requires` ### Merge From 95e32df7b6c1bfa3f34462d52de3ad3a290c7276 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Thu, 7 Nov 2024 13:19:56 +0100 Subject: [PATCH 4/4] Added Error Code --- spec/Section 4 -- Composition.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 1870190..005ffe2 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -20,6 +20,8 @@ run in sequence to produce the composite execution schema. LOOKUP_MUST_NOT_RETURN_LIST +**Severity** ERROR + **Formal Specification** - Let {fields} be the set of all field definitions annotated with `@lookup` in the schema.