Skip to content
Draft
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
59 changes: 54 additions & 5 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -1096,15 +1096,49 @@ Object type extensions have the potential to be invalid if incorrectly defined.
1. The named type must already be defined and must be an Object type.
2. The fields of an Object type extension must have unique names; no two fields
may share the same name.
3. Any fields of an Object type extension must not be already defined on the
previous Object type.
4. Any non-repeatable directives provided must not already apply to the previous
3. Any non-repeatable directives provided must not already apply to the previous
Object type.
5. Any interfaces provided must not be already implemented by the previous
4. Any interfaces provided must not be already implemented by the previous
Object type.
6. The resulting extended object type must be a super-set of all interfaces it
5. The resulting extended object type must be a super-set of all interfaces it
implements.

#### Field Extensions

Field extensions are used to represent a field which has been extended from some
Comment on lines +1106 to +1108
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move this before the Type Validation and do not mention "Field extensions"?

Instead make a part of "type extension"?

previously defined field. For example this may be used by a GraphQL service
which is itself an extension of another GraphQL service. When the same field
appears in multiple extensions, the properties are merged with later extensions
taking precedence for conflicting values.

In this example, we can deprecate the field `field` on type `Query` by using a
field extension:
Comment on lines +1114 to +1115
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. I'd phrase that as a "type extension that adds deprecation to the type fields":

Suggested change
In this example, we can deprecate the field `field` on type `Query` by using a
field extension:
In this example, we can deprecate the field `field` on type `Query` by adding a `@deprecated` directive through a type extension:


```graphql example
type Query {
field: String
}
```

```graphql example
extend type Query {
field: String @deprecated(reason: "Use newField")
}
```

** Type Validation **

Fields have the potential to be invalid if incorrectly defined.

1. The field type must match the previous definition exactly
2. The default argument definitions may not be changed or removed.
3. The description may be added if none exists, or must match the existing
description exactly
Comment on lines +1134 to +1136
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we either:

  1. allow both descriptions and defaultValues if they match exactly.
    or
  2. forbid both descriptions and defaultValues in object extensions.

Slight preference for 1. because it's consistent with what we do for checking the type. But I can see how 2. is maybe simpler to implement.

4. The deprecation reason may be added if none exists, or must match the
existing reason exactly
5. Directives may be added but cannot conflict with existing non-repeatable
directives
Comment on lines +1137 to +1140
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should remove 4. as a sub-case of 5. @deprecated is not repeatable so it's not valid to add @deprecated from a type extension, even if it's the exact same deprecation reason.


## Interfaces

InterfaceTypeDefinition :
Expand Down Expand Up @@ -1358,6 +1392,21 @@ defined.
6. The resulting extended Interface type must be a super-set of all Interfaces
it implements.

#### Interface Field Extensions

Interface field extensions follow the same rules as Object field extensions and
are used to extend fields on interface types.

```graphql example
interface Node {
id: ID
}

extend interface Node {
id: ID @deprecated(reason: "Use globalId instead")
}
```

## Unions

UnionTypeDefinition : Description? union Name Directives[Const]?
Expand Down