Commit Graph

678 Commits

Author SHA1 Message Date
Adrian Philipp
b3791378fa Return early if rules are empty to avoid visiting elements
This is tested already in testPassesValidationWithEmptyRules
2018-04-12 17:36:24 +02:00
Vladimir Razuvaev
568cae584b
Merge pull request #260 from simPod/drop-unsupported-php
Drop support for EOL PHP versions
2018-04-08 20:37:29 +08:00
Vladimir Razuvaev
ccbc91a97f
Merge pull request #267 from ruudk/patch-1
Fix missing sprintf in Schema.php
2018-04-06 17:14:58 +08:00
Ruud Kamphuis
66108bec84
Fix missing sprintf 2018-04-05 17:14:28 +02:00
Vladimir Razuvaev
87729589e0
Merge pull request #265 from sarukuku/master
Add content type header to curl commands on server example
2018-04-05 14:47:40 +08:00
sarukuku
9b94ac2f06 Better argument order for curl. Related to #264. 2018-04-04 16:34:05 +03:00
sarukuku
f2678b4a10 Add content type header to curl. This fixes #264. 2018-04-04 16:26:57 +03:00
Simon Podlipsky
bcf396868a
Drop support for EOL PHP versions 2018-03-30 14:48:49 +02:00
Vladimir Razuvaev
5c57d3b379 Note in UPGRADE.md about changes in input format of the Standard Server 2018-03-29 20:31:31 +08:00
Vladimir Razuvaev
b141ed2d72 Merge branch 'master' of https://github.com/webonyx/graphql-php 2018-03-29 20:30:32 +08:00
Vladimir Razuvaev
7762430bc3
Merge pull request #256 from camuthig/fix-operation-param-operation-name
Parse operation name from operationName instead of operation
2018-03-29 20:25:39 +08:00
Chris Muthig
68eb325d18
Add a unit test covering the operationName parsing 2018-03-28 13:55:59 -07:00
Vladimir Razuvaev
a1b1436f7d Remove notice about removing typeConfigDecorator from UPGRADE.md since we reverted this change and it still exists 2018-03-26 12:28:11 +08:00
Vladimir Razuvaev
2913f07050
Merge pull request #258 from ScullWM/patch-1
Fix Symfony PSR7 link
2018-03-26 12:17:24 +08:00
Vladimir Razuvaev
45baa5f185
Merge pull request #248 from danez/012
Port 0.12.3 changes from graphql-js
2018-03-26 11:43:59 +08:00
Daniel Tschinder
3e067cc60f Readd type decorator and fix lazy type loading 2018-03-06 12:53:28 +01:00
Thomas P
2a4c0a111a
Fix Symfony PSR7 link
Previous URL no longer exist and return a 404.
I've update the url to https://symfony.com/doc/current/components/psr7.html
2018-03-05 15:06:38 +01:00
Chris Muthig
8aa6dc17a5
Parse operation name from operationName instead of operation 2018-03-03 15:41:55 -08:00
Daniel Tschinder
f9a366e69a Add Fallback for DirectiveLocations 2018-02-16 16:54:06 +01:00
Daniel Tschinder
61fe317faf Update docs 2018-02-16 16:50:38 +01: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
48c5e64a08 Adding an interface to a type is now a dangerous change.
ref: graphql/graphql-js#992
2018-02-16 15:30:27 +01:00
Daniel Tschinder
d71b45d60e Find breaking directive changes
ref: graphql/graphql-js#1152
2018-02-16 00:15:19 +01:00
Daniel Tschinder
ddfeee314c Fix path argument. Enchance visit test to validate all arguments
ref: graphl/graphql-js#1149
2018-02-15 22:44:17 +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
949b853678 Add experimental support for parsing variable definitions in fragments
ref: graphql/graphql-js#1141
2018-02-15 13:37:45 +01:00
Daniel Tschinder
fde7df534d Robust type info
There are possibilities for errors during validation if a schema is not valid when provided to TypeInfo. Most checks for validity existed, but some did not. This asks flow to make those checks required and adds the remaining ones. Important now that we allow construction of invalid schema.

ref: graphql/graphql-js#1143
2018-02-15 12:22:29 +01:00
Daniel Tschinder
97e8a9e200 Move schema validation into separate step (type constructors)
This is the second step of moving work from type constructors to the schema validation function.

ref: graphql/graphql-js#1132
2018-02-15 12:14:08 +01:00
Daniel Tschinder
6d08c342c9 Address recent SDL spec changes
This should be the last set of spec changes for a standardized SDL

ref: graphql/graphql-js#1139
2018-02-13 18:18:50 +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
9387548aa1 Better Predicates
Introduces new assertion functions for each kind of type mirroring the existing ones for the higher order types.

ref: graphql/graphql-js#1137
2018-02-13 18:04:03 +01:00
Daniel Tschinder
60df83f47e Preserve original coercion errors, improve error quality.
This is a fairly major refactoring of coerceValue which returns an Either so it can return a complete collection of errors. This allows originalError to be preserved for scalar coercion errors and ensures *all* errors are represented in the response.

This had a minor change to the logic in execute / subscribe to allow for buildExecutionContext to abrupt complete with multiple errors.

ref: graphql/graphql-js#1133
2018-02-13 16:51:44 +01:00
Daniel Tschinder
6d45a22ba4 Always extract extensions from the original error if possible
ref: graphql/graphql-js#2d08496720088dbe65ebea312c8526bd48fb8ee8
2018-02-13 10:42:56 +01:00
Daniel Tschinder
cf276340a4 Fix printError/locations for multiple nodes.
If a GraphQLError represents multiple nodes across files (could happen for validation across multiple parsed files) then the reported locations and printError output can be incorrect for the second node. This ensures locations are derived from nodes whenever possible to get correct location and amends comment documentation.
ref: graphql/graphql-js#1131
2018-02-13 10:42:51 +01:00
Daniel Tschinder
06c6c4bd97 Validate schema root types and directives
This moves validation out of GraphQLSchema's constructor (but not yet from other type constructors), which is responsible for root type validation and interface implementation checking.

Reduces time to construct GraphQLSchema significantly, shifting the time to validation.

This also allows for much looser rules within the schema builders, which implicitly validate while trying to adhere to flow types. Instead we use any casts to loosen the rules to defer that to validation where errors can be richer.

This also loosens the rule that a schema can only be constructed if it has a query type, moving that to validation as well. That makes flow typing slightly less nice, but allows for incremental schema building which is valuable

ref: graphql/graphql-js#1124
2018-02-13 10:42:35 +01:00
Daniel Tschinder
15374a31dd New: printError()
Lifted from / inspired by a similar change in graphql/graphql-js#722, this creates a new function `printError()` (and uses it as the implementation for `GraphQLError#toString()`) which prints location information in the context of an error.

This is moved from the syntax error where it used to be hard-coded, so it may now be used to format validation errors, value coercion errors, or any other error which may be associated with a location.

ref: graphql/graphql-js

BREAKING CHANGE: The SyntaxError message does not contain the codeframe anymore and only the message, (string) $error will print the codeframe.
2018-02-12 12:23:39 +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
481cdc9a82 Include test that printSchema includes non-spec directives.
ref: graphql/graphql-js@007407deb0

Also fixes expected <-> actual in this testfile
2018-02-11 21:32:40 +01:00
Daniel Tschinder
0c984a83bb Allow constructing GraphQLError with single node.
A common case is encountering an error which blames to a single AST node. Ensure the GraphQLError constructor can handle this case.

ref: graphql/graphql-js#1123
2018-02-11 21:18:54 +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
74854d55a0 Read-only AST types
ref: graphql/graphql-js#1121
2018-02-11 18:28:34 +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