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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
123 changes: 122 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,127 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we try to keep the error codes <~35 characters?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe REQUIRED_FIELD_ARGUMENT_MISSING?


**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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Let {typeNames} be the set of all object and interface types names from all
- Let {typeNames} be the set of all object and interface type names from all

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
that field . In other words, arguments are effectively merged by intersection:
that field. In other words, arguments are effectively merged by intersection:

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you not mean by union?

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

The spec doesn't mention directive arguments?


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] @shareable
}

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

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
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] @shareable
}

# Schema B
type Query {
books: [Book] @shareable
}
```

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