graphql-php/tests/Validator
Daniel Tschinder 7b05673d8d Validation: improving overlapping fields quality
This improves the overlapping fields validation performance and improves error reporting quality by separating the concepts of checking fields "within" a single collection of fields from checking fields "between" two different collections of fields. This ensures for deeply overlapping fields that nested fields are not checked against each other repeatedly. Extending this concept further, fragment spreads are no longer expanded inline before looking for conflicts, instead the fields within a fragment are compared to the fields with the selection set which contained the referencing fragment spread.

e.g.

```graphql
{
  same: a
  same: b
  ...X
}

fragment X on T {
  same: c
  same: d
}
```

In the above example, the initial query body is checked "within" so `a` is compared to `b`. Also, the fragment `X` is checked "within" so `c` is compared to `d`. Because of the fragment spread, the query body and fragment `X` are checked "between" so that `a` and `b` are each compared to `c` and `d`. In this trivial example, no fewer checks are performed, but in the case where fragments are referenced multiple times, this reduces the overall number of checks (regardless of memoization).

**BREAKING**: This can change the order of fields reported when a conflict arises when fragment spreads are involved. If you are checking the precise output of errors (e.g. for unit tests), you may find existing errors change from `"a" and "c" are different fields` to `"c" and "a" are different fields`.

From a perf point of view, this is fairly minor as the memoization "PairSet" was already keeping these repeated checks from consuming time, however this will reduce the number of memoized hits because of the algorithm improvement.

From an error reporting point of view, this reports nearest-common-ancestor issues when found in a fragment that comes later in the validation process. I've added a test which fails with the existing impl and now passes, as well as changed a comment.

This also fixes an error where validation issues could be missed because of an over-eager memoization. I've also modified the `PairSet` to be aware of both forms of memoization, also represented by a previously failing test.

ref: graphql/graphql-js#386
2018-02-11 17:45:35 +01:00
..
AbstractQuerySecurityTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
ArgumentsOfCorrectTypeTest.php Fix KnownDirectives validator to support all directives 2018-02-11 13:15:51 +01:00
DefaultValuesOfCorrectTypeTest.php Cleaning up old unused messages 2016-12-06 03:45:52 +07:00
DisableIntrospectionTest.php Adds tests for DisableIntrospection Validation rule 2017-06-17 14:49:07 +02:00
ExecutableDefinitionsTest.php Update to match SDL changes 2018-02-11 13:27:26 +01:00
FieldsOnCorrectTypeTest.php Ability to load types in schema on demand (#69) 2017-03-05 03:26:22 +07:00
FragmentsOnCompositeTypesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
KnownArgumentNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
KnownDirectivesTest.php Update to match SDL changes 2018-02-11 13:27:26 +01:00
KnownFragmentNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
KnownTypeNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
LoneAnonymousOperationTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
NoFragmentCyclesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
NoUndefinedVariablesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
NoUnusedFragmentsTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
NoUnusedVariablesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
OverlappingFieldsCanBeMergedTest.php Validation: improving overlapping fields quality 2018-02-11 17:45:35 +01:00
PossibleFragmentSpreadsTest.php Ability to load types in schema on demand (#69) 2017-03-05 03:26:22 +07:00
ProvidedNonNullArgumentsTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
QueryComplexityTest.php Abstract base class for validation rules 2017-08-18 20:56:04 +07:00
QueryDepthTest.php Updated introspection query and related tests for recent changes 2016-10-19 01:35:18 +07:00
QuerySecuritySchema.php Fix KnownDirectives validator to support all directives 2018-02-11 13:15:51 +01:00
ScalarLeafsTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
TestCase.php Update to match SDL changes 2018-02-11 13:27:26 +01:00
UniqueArgumentNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
UniqueDirectivesPerLocationTest.php Added validation rule for unique directives per location 2016-11-19 00:21:56 +07:00
UniqueFragmentNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
UniqueInputFieldNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
UniqueOperationNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
UniqueVariableNamesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
ValidationTest.php Fix KnownDirectives validator to support all directives 2018-02-11 13:15:51 +01:00
VariablesAreInputTypesTest.php Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
VariablesInAllowedPositionTest.php Cleaning up old unused messages 2016-12-06 03:45:52 +07:00