@@ -5841,58 +5841,72 @@ ERROR
5841
5841
5842
5842
**Formal Specification **
5843
5843
5844
- - Let {schema } be the merged composite execution schema .
5845
- - Let {compositeTypes} be the set of all composite types in {schema }.
5844
+ - Let {schemas } be all source schemas .
5845
+ - Let {compositeTypes } be the set of all composite types in {schemas }.
5846
5846
- For each {composite } in {compositeTypes }:
5847
5847
- Let {fields } be the set of fields on {composite }.
5848
5848
- Let {arguments } be the set of all arguments on {fields }.
5849
5849
- For each {argument } in {arguments }:
5850
5850
- If {argument } is **not ** annotated with `@require `:
5851
5851
- Continue
5852
+ - Let {schema } be the schema that defines {argument}.
5853
+ - Let {declaringField } be the field that defines {argument }.
5854
+ - Let {declaringType } be the type that defines {declaringField }.
5855
+ - Let {otherSchemas } be the set of all {schemas } excluding {schema }.
5852
5856
- Let {fieldArg } be the string value of the `field ` argument of the
5853
5857
`@require ` directive on {argument }.
5854
5858
- Let {parsedFieldArg } be the parsed selection map from {fieldArg }.
5855
- - {ValidateSelectionMap (parsedFieldArg, parentType)} must be true .
5859
+ - {ValidateSelectionMap (parsedFieldArg, declaringType, otherSchemas)} must
5860
+ be true .
5856
5861
5857
- ValidateSelectionMap (selectionMap, parentType ):
5862
+ ValidateSelectionMap (selectionMap, declaringType, schemas ):
5858
5863
5859
5864
- For each {selection } in {selectionMap }:
5860
- - Let {field } be the field selected by {selection } on {parentType }.
5861
- - If {field } is **not ** defined on {parentType }:
5865
+ - Let {possibleTypes } be the set of all possible types for {declaringType } in
5866
+ {schemas }.
5867
+ - Let {field } be the first field selected by {selection } on any
5868
+ {possibleTypes }.
5869
+ - If no {field } is found
5862
5870
- return false
5863
5871
- Let {fieldType } be the type of {field}.
5864
5872
- If {fieldType } is not a scalar type
5865
- - Let {subSelections } be the selections in {selection }
5866
- - If {subSelections } is empty
5873
+ - Let {subSelectionSet } be the selection set of {selection }
5874
+ - If {subSelectionSet } is empty
5867
5875
- return false
5868
- - If {ValidateSelectionMap (subSelections , fieldType)} is false
5876
+ - If {ValidateSelectionMap (subSelectionSet , fieldType, schemas )} is false
5869
5877
- return false
5870
5878
- return true
5871
5879
5872
5880
**Explanatory Text **
5873
5881
5874
5882
Even if the selection map for `@require (field : " …" )` is syntactically valid , its
5875
- contents must also be valid within the composed schema . Fields must exist on the
5876
- parent type for them to be referenced by ` @require `. In addition, fields
5877
- requiring unknown fields break the valid usage of `@require `, leading to a
5878
- `REQUIRE_INVALID_FIELDS` error.
5883
+ contents must also be valid . Required fields must exist on the parent type in a
5884
+ ** different schema than the one defining the requirement** for them to be
5885
+ referenced by `@require `. Additionally, requiring unknown fields invalidates
5886
+ `@require `, resulting in a ` REQUIRE_INVALID_FIELDS` error.
5879
5887
5880
5888
**Examples**
5881
5889
5882
5890
In the following example, the `@require ` directive's `field` argument is a valid
5883
5891
selection set and satisfies the rule.
5884
5892
5885
5893
```graphql example
5894
+ ## Schema A
5886
5895
type User @key (fields : " id" ) {
5887
5896
id : ID !
5888
- name : String !
5889
5897
profile (name : String ! @require (field : "name" )): Profile
5890
5898
}
5891
5899
5892
5900
type Profile {
5893
5901
id : ID !
5894
5902
name : String
5895
5903
}
5904
+
5905
+ ## Schema B
5906
+ type User @key (fields : " id" ) {
5907
+ id : ID !
5908
+ name : String
5909
+ }
5896
5910
```
5897
5911
5898
5912
In this counter -example , the `@require ` directive does not have a valid
@@ -5920,6 +5934,17 @@ type Book {
5920
5934
}
5921
5935
```
5922
5936
5937
+ In the following counter -example , the `@require ` directive references a field from itself
5938
+ (`Book.size`) which is not allowed . This results in a `REQUIRE_INVALID_FIELDS ` error .
5939
+
5940
+ ```graphql counter -example
5941
+ type Book {
5942
+ id : ID !
5943
+ size : Int
5944
+ pages (pageSize : Int @require (field : " size" )): Int
5945
+ }
5946
+ ```
5947
+
5923
5948
### Validate Shareable Directives
5924
5949
5925
5950
#### Invalid Field Sharing
0 commit comments