Commit Graph

48 Commits

Author SHA1 Message Date
Simon Podlipsky
caa50d6db9
Fix CS in tests/Validator 2018-09-02 13:08:49 +02:00
Simon Podlipsky
715146cdd1
Add void return typehint to test methods 2018-08-31 14:41:18 +02:00
Simon Podlipsky
a30b3104a0
Replace misleading @it by @see annotation 2018-08-31 10:55:14 +02:00
Vladimir Razuvaev
672ff0b7d6 Add nested nullable test in VariablesInAllowedPosition 2018-08-22 17:55:42 +07:00
Simon Podlipsky
4c327a6c16
Fix CS in Validator folder 2018-08-08 10:44:05 +02:00
Simon Podlipsky
24b6b736b2
Upgrade PHPUnit 2018-07-29 19:01:39 +02:00
Daniel Tschinder
5e7cf2aacb Skip test on PHP < 7 2018-02-16 16:47:11 +01:00
Daniel Tschinder
dc6e814de3 Fix orList to be the same as in JS and follow the chicago style for commas 2018-02-16 16:39:59 +01:00
Daniel Tschinder
d92a2dab21 Add suggestions for invalid values
For misspelled enums or field names, these suggestions can be helpful.

This also changes the suggestions algorithm to better detect case-sensitivity mistakes, which are common

ref: graphql/graphql-js#1153
2018-02-16 16:19:25 +01:00
Daniel Tschinder
58e0c7a178 Validate literals in a single rule with finer precision
This generalizes the "arguments of correct type" and "default values of correct type" to a single rule "values of correct type" which has been re-written to rely on a traversal rather than the utility function `isValidLiteralValue`. To reduce breaking scope, this does not remove that utility even though it's no longer used directly within the library. Since the default values rule included another validation rule that rule was renamed to a more apt "variable default value allowed".

This also includes the original errors from custom scalars in the validation error output, solving the remainder of graphql/graphql-js#821.

ref: graphql/graphql-js#1144
2018-02-15 21:29:14 +01:00
Daniel Tschinder
17520876d8 Update some validators to latest upstream version
This includes:
graphql/graphql-js#1147
graphql/graphql-js#355

This also fixes two bugs in the Schema
 - types that were not found where still added to the typeMap
 - InputObject args should not be searched for types.
2018-02-15 17:19:53 +01:00
Daniel Tschinder
50cbfb4a44 Fix Bug in PossibleFragmentSpreads validator
ref: graphql/graphql-js@7e147a8dd6
2018-02-13 18:08:05 +01:00
Daniel Tschinder
f661f38215 Fix unhandled error when parsing custom scalar literals.
This factors out the enum value validation from scalar value validation and ensures the same try/catch is used in isValidLiteralValue as isValidPHPValue and protecting from errors in valueFromAST.
ref: graphql/graphql-js#1126
2018-02-11 22:31:04 +01:00
Daniel Tschinder
b5106a06c9 SDL Spec changes
This adds the recent changes to the SDL proposal.

ref: graphql/graphql-js#1117
2018-02-11 21:08:53 +01:00
Daniel Tschinder
ff63e07b05 Improve introspection types + new getIntrospectionQuery()
This adds a new function `getIntrospectionQuery()` which allows for some minor configuration over the resulting query text: to exclude descriptions if your use case does not require them.

ref: graphql/graphql-js#1113
2018-02-11 18:19:52 +01:00
Daniel Tschinder
6e358eb26c Fix infinite loop on invalid queries in OverlappingFields
`OverlappingFieldsCanBeMerged` would infinite loop when passed something like

```graphql
fragment A on User {
  name
  ...A
}
```

It's not `OverlappingFieldsCanBeMerged`'s responsibility to detect that validation error, but we still would ideally avoid infinite looping.

This detects that case, and pretends that the infinite spread wasn't there for the purposes of this validation step.

Also, by memoizing and checking for self-references this removes duplicate reports.

ref: graphql/graphql-js#1111
2018-02-11 17:58:48 +01:00
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
Daniel Tschinder
58453c31f7 Improve validation error message when field names conflict
ref: graphql/graphql-js#363
2018-02-11 14:11:21 +01:00
Daniel Tschinder
d70a9a5e53 Update to match SDL changes
This changes the parsing grammar and validation rules to more correctly implement the current state of the GraphQL SDL proposal (facebook/graphql#90)

ref: graphql/graphl-js#1102
2018-02-11 13:27:26 +01:00
Daniel Tschinder
0c32982171 Fix KnownDirectives validator to support all directives 2018-02-11 13:15:51 +01:00
Daniel Tschinder
4e26de3588 Support for union types when using buildSchema
* Adds support for resolving union/interface types when using a generated schema
* Move resolveType __typename checking into defaultResolveType
* Clean up existing tests and improve error messages

ref: graphql/graphql-js#947

# Conflicts:
#	src/Utils/BuildSchema.php
#	tests/Utils/BuildSchemaTest.php
2018-02-10 18:45:01 +01:00
Vladimir Razuvaev
203fddfe4e Abstract base class for validation rules 2017-08-18 20:56:04 +07:00
Vladimir Razuvaev
37a42ededd Query validation should pass if empty array of rules is provided 2017-07-13 02:39:24 +07:00
Vladimir Razuvaev
9551569ffe Merge branch 'lazy-types' into v0.10
# Conflicts:
#	src/Executor/Executor.php
2017-07-10 17:11:41 +07:00
Vladimir Razuvaev
30632050a5 Validation: added test cases to check support for good negative floats and ints 2017-07-05 18:35:45 +07:00
Vladimir Razuvaev
b47c87f793 Allow null values for enums 2017-07-04 20:19:52 +07:00
Vladimir Razuvaev
7937b15855 Fixed several typos 2017-07-03 18:04:32 +07:00
Laurin Quast
6d6d1ac01b Adds tests for DisableIntrospection Validation rule 2017-06-17 14:49:07 +02:00
Vladimir Razuvaev
bc4b990946 Do not run query complexity validation if there were other validation errors (as it will throw and mess up previous validation results), see #125 2017-06-03 17:07:01 +07:00
Pascal de Vink
11a1b13b72
Use directives to calculate query complexity 2017-04-24 14:21:58 +02:00
Vladimir Razuvaev
ce9bf33f20 Ability to load types in schema on demand (#69) 2017-03-05 03:26:22 +07:00
vladar
c5bba0e7d4 Cleaning up old unused messages 2016-12-06 03:45:52 +07:00
vladar
f672f0c90c Added validation rule for unique directives per location 2016-11-19 00:21:56 +07:00
vladar
8a676cde99 Support for NullValue 2016-11-18 23:59:28 +07:00
vladar
5d889ccacd Reverted several breaking changes from #75; tests are green 2016-11-16 18:37:35 +07:00
Andreas Heiberg
d8ca5f4183 move to NodeType enum 2016-11-16 18:07:56 +07:00
vladar
c11f25794a Deprecated callbacks in "type" option of field/argument definitions (see #35) 2016-10-23 00:49:25 +07:00
vladar
2675b65095 Moved all error-related classes to separate namespace; fixed related broken tests 2016-10-21 16:40:56 +07:00
vladar
0a79be8409 Updated introspection query and related tests for recent changes 2016-10-19 01:35:18 +07:00
vladar
236021acf8 Added deprecated directive; changed custom directives handling in schema; various minor tweaks 2016-10-19 01:34:46 +07:00
vladar
e82f887918 Fixed visitor; more visitor tests 2016-09-14 18:41:02 +07:00
vladar
3dec7a9995 Test complete validation 2016-09-14 18:41:02 +07:00
vladar
800d8ba25f Continue updating validator rules for april2016 spec 2016-09-14 18:41:02 +07:00
vladar
f1ddc98390 Updating validator rules for april2016 spec 2016-09-14 18:41:02 +07:00
Jeremiah VALERIE
545fe616a0 Add Complexity and Depth Query Security 2016-04-09 15:31:07 +02:00
Jeremiah VALERIE
1bc5e0c9da Use PSR-4 Autoloader for tests 2016-04-09 14:14:40 +02:00
vladar
841d6ab851 Updated to latest version of graphql-js 2015-08-17 20:01:55 +06:00
vladar
20c482ce2f Version 0.1 2015-07-15 23:05:46 +06:00