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_WITH_MISSING_REQUIRED_ARGUMENT #101

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 120 additions & 1 deletion spec/Section 4 -- Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,7 @@ enum Genre {

**Error Code:**

`REQUIRED_INPUT_FIELD_MISSING_IN_SOME_SUBGRAPH`
`REQUIRED_INPUT_FIELD_MISSING_IN_SOME_SCHEMA`

**Severity:**

Expand Down Expand Up @@ -3179,6 +3179,125 @@ input BookFilter {
In this invalid case, `title` is mandatory in Schema A but not defined in
`Schema B`, causing inconsistency in required fields across schemas.

#### Required Argument Missing

**Error Code:**
`REQUIRED_ARGUMENT_MISSING_IN_SOME_SCHEMA`
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

**Severity:**
ERROR
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

**Formal Specification:**

- Let {typeNames} be the set of all object and interface types names from all
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
source schemas that are not declared as `@internal`
- For each {typeName} in {typeNames}:
- Let {typeDefinitions} be the list of all type definitions from different
source schemas with the name {typeName}.
- Let {fieldNames} be the set of all field names from all {typeDefinitions}
that are not declared as `@internal`.
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
- For each {fieldName} in {fieldNames}:
- Let {fieldDefinitions} be the list of all field definitions from
{typeDefinitions} with the name {fieldName}.
- Let {requiredArgumentNames} be the set of all argument names from
{fieldDefinitions} that have a non-nullable type in at least one
definition that does not specify `@require`
- For each {fieldDefinition} in {fieldDefinitions}:
- For each {requiredArgumentName} in {requiredArgumentNames}:
- {fieldDefinition} must have an argument with the name
{requiredArgumentName} that does not specify `@require`

**Explanatory Text:**

When merging a field definition across multiple schemas, any argument that is
non-null (i.e., “required”) in one schema must appear in all schemas that define
that field . In other words, arguments are effectively merged by intersection:
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
if an argument is considered required in any schema, then that same argument
must exist in every schema that contributes to the composite definition. If a
required argument is missing in one schema, there is no consistent way to define
that field or directive across schemas.
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

If an argument is marked with `@require`, it is treated as non-required.
Consequently, this argument must either be nullable in all other schemas or must
also be marked with `@require` in all other schemas.

**Examples**

All schemas agree on having a required argument `author` for the `books` field:

```graphql example
# Schema A
type Query {
books(author: String!): [Book]
}

# Schema B
type Query {
books(author: String!): [Book]
}
```

In the following example, the `author` argument on the `books` field in Schema A
specifies a dependency on the `author` field in Schema C. The `author` argument
on the `books` field in Schema B is optional. As a result, the composition
succeeds; however, the `author` argument will not be included in the composite
schema.

```graphql example
# Schema A
type Collection {
books(author: String! @require(field: "author")): [Book] @shareable
}

# Schema B
type Collection {
books(author: String): [Book] @shareable
}

# Schema C
type Collection {
author: String!
}
```

In the following counter example, the `author` argument is required in one
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
schema but not in the other. This will result in a
`REQUIRED_ARGUMENT_MISSING_IN_SOME_SCHEMA` error.

```graphql counter-example
# Schema A
type Query {
books(author: String!): [Book]
}

# Schema B
type Query {
books: [Book]
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
}
```

In the following counter-example, the `author` argument on the `books` field in
Schema A specifies a dependency on the `author` field in Schema C. The `author`
argument on the `books` field in Schema B is **NOT** optional. This will result
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
in a `REQUIRED_ARGUMENT_MISSING_IN_SOME_SCHEMA` error.

```graphql counter-example
# Schema A
type Collection {
books(author: String! @require(field: "author")): [Book] @shareable
}

# Schema B
type Collection {
books(author: String!): [Book] @shareable
}

# Schema C
type Collection {
author: String!
}
```

#### Output Field Argument Types Mergeable

**Error Code**
Expand Down
Loading