Commit Graph

294 Commits

Author SHA1 Message Date
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
c4f11a577e Allow to extend GraphQL errors with additional properties
ref: graphql/graphql-js#928
2018-02-10 18:45:38 +01:00
Daniel Tschinder
2cbccb87db Remove duplicated code from buildASTSchema and extendSchema
ref: graphql/graphql-js#1000

BREAKING CHANGE: SchemaBuilder::build() and buildAST() and constructor
removed the typedecorator, as not needed anymore as library can now resolve
union and interfaces from generated schemas.
2018-02-10 18:45:32 +01:00
Daniel Tschinder
27ce24b5fe Fix parsing of default values in build-schema
* Generalizes building a value from an AST, since "scalar" could be misleading, and supporting variable values within custom scalar literals can be valuable.
* Replaces isNullish with isInvalid since `null` is a meaningful value as a result of literal parsing.
* Provide reasonable default version of 'parseLiteral'

ref: 714ee980aa
ref: https://github.com/graphql/graphql-js/pull/903

# Conflicts:
#	src/Utils/BuildSchema.php
#	tests/Utils/BuildSchemaTest.php
2018-02-10 18:45:23 +01:00
Daniel Tschinder
2123946dbd Add warnings for nullable changes
ref: db4cfdc31d
ref: graphql/graphql-js#1096

# Conflicts:
#	tests/Utils/FindBreakingChangesTest.php
2018-02-10 18:45:18 +01:00
Daniel Tschinder
98e397ce44 Add additional number lexing test
ref: graphql/graphql-js#72421378550cf51b13c6db59b8fc912591fd1a4b
2018-02-10 18:45:06 +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
Daniel Tschinder
7705e50e44 Fix print of block string with leading space and quotation
ref: graphql/graphql-js#1190
2018-02-10 18:44:56 +01:00
Daniel Tschinder
022c490011 RFC: Descriptions as strings
As discussed in facebook/graphql#90

This proposes replacing leading comment blocks as descriptions in the schema definition language with leading strings (typically block strings).

While I think there is some reduced ergonomics of using a string literal instead of a comment to write descriptions (unless perhaps you are accustomed to Python or Clojure), there are some compelling advantages:

* Descriptions are first-class in the AST of the schema definition language.
* Comments can remain "ignored" characters.
* No ambiguity between commented out regions and descriptions.

Specific to this reference implementation, since this is a breaking change and comment descriptions in the experimental SDL have fairly wide usage, I've left the comment description implementation intact and allow it to be enabled via an option. This should help with allowing upgrading with minimal impact on existing codebases and aid in automated transforms.

BREAKING CHANGE: This does not parse descriptions from comments by default anymore and the value of description in Nodes changed from string to StringValueNode
2018-02-10 18:44:51 +01:00
Daniel Tschinder
e65638f6f4 Improvements to printing block strings
ref: graphql/graphql-js#f9e67c403a4667372684ee8c3e82e1f0ba27031b
2018-02-10 18:44:45 +01:00
Daniel Tschinder
8747ff8954 RFC: Block String
This RFC adds a new form of `StringValue`, the multi-line string, similar to that found in Python and Scala.

A multi-line string starts and ends with a triple-quote:

```
"""This is a triple-quoted string
and it can contain multiple lines"""
```

Multi-line strings are useful for typing literal bodies of text where new lines should be interpretted literally. In fact, the only escape sequence used is `\"""` and `\` is otherwise allowed unescaped. This is beneficial when writing documentation within strings which may reference the back-slash often:

```
"""
In a multi-line string \n and C:\\ are unescaped.
"""
```

The primary value of multi-line strings are to write long-form input directly in query text, in tools like GraphiQL, and as a prerequisite to another pending RFC to allow docstring style documentation in the Schema Definition Language.

Ref: graphql/graphql-js#926
2018-02-10 18:43:26 +01:00
Daniel Tschinder
46816a7cda Uniform parsing of queries with short-hand syntax with regular queries 2018-02-09 14:33:04 +01:00
Daniel Tschinder
eb9ac66af8 Fix how TypeInfo handles inline fragments without type
ref: graphql/graphql-js#1041
2018-02-09 14:32:44 +01:00
Vladimir Razuvaev
4f223ba11d Fixed PSR request parsing, broken after recent changes 2018-01-13 18:08:07 +07:00
Vladimir Razuvaev
918bbff2bd
Merge branch 'master' into no-parsing 2018-01-13 17:20:00 +07:00
Vladimir Razuvaev
9944a689bf Exclude nulls from serialized AST 2018-01-13 16:25:06 +07:00
Vladimir Razuvaev
8b17953fe5 Fixed bug preventing use of parser noLocation option for serialization / deserialization 2018-01-13 15:45:09 +07:00
Adrien Crivelli
5cbaf973e1
Leverage PHPUnit setExpectedException() instead of custom code
Closes #219
2018-01-01 18:06:08 +09:00
Adrien Crivelli
178b179db3
Drop support non pre-parsed PSR-7 request body
This revert #202 (commit 9d37f4c) because trying to parse PSR-7 request
was a mistake. The whole point of PSR-7 is to allow for interoperability
and be able to use specialized libs for body parsing (amongst many other
things). Trying to parse ourselves would be opening a can of worm if/when
other content types have to be supported. It is more correct and future
safe to require that the body is parsed before being passed to GraphQL.
2017-12-21 15:01:57 +09:00
Jáchym Toušek
f6c3fe3758
indentation 2017-12-12 13:36:20 +01:00
Jáchym Toušek
9e2c1dae87
Add test 2017-12-12 09:53:15 +01:00
Vladimir Razuvaev
9c563d5c00
Merge pull request #199 from roippi/findbreakingchanges
port findBreakingChanges
2017-11-28 20:14:36 +07:00
Adrien Crivelli
11c9429fab
Support non pre-parsed PSR-7 request body
Because PSR-7 specification only specify that `getParsedBody()` **may**
return the parsed body for `application/json`, we cannot assume that it
is always the case. So if the value returned parsed body is an empty array,
it means we should try to parse it ourselves (`null` would mean no body at
all according to spec).

With this modification we try to used given parsed body, but fallback on
trying to parse the body if necessary. This leave the door open to custom
implementation of parsing if needed, while making it easier to use out of
the box.
2017-11-26 19:57:32 +09:00
Ben Roberts
b18dfd670f testFindsAllDangerousChanges 2017-11-21 12:30:18 -05:00
Ben Roberts
533b8b8b5f testDetectsAdditionsToUnionType 2017-11-21 12:18:28 -05:00
Ben Roberts
e0a63ec792 testDetectsEnumValueAdditions 2017-11-21 11:53:14 -05:00
Ben Roberts
c4ae03454a testFindDangerousArgChanges 2017-11-21 11:50:11 -05:00
Ben Roberts
3c0ed787ba testDetectsAllBreakingChanges 2017-11-21 11:33:45 -05:00
Ben Roberts
dbccf9b196 testDetectsRemovalOfInterfaces 2017-11-20 14:39:06 -05:00
Ben Roberts
0bb689d340 testArgsThatMoveAwayFromNonNull 2017-11-20 14:12:26 -05:00
Ben Roberts
90f35f26a2 testDoesNotFlagArgsWithSameTypeSignature 2017-11-20 13:57:52 -05:00
Ben Roberts
0fd5abc833 testDetectsAdditionOfFieldArg 2017-11-20 13:48:21 -05:00
Ben Roberts
42d8ac07f9 testDetectsFieldArgumentTypeChange 2017-11-20 12:52:49 -05:00
Ben Roberts
4ea6cbe839 bugfix var ref 2017-11-17 17:35:33 -05:00
Ben Roberts
fc9c5e85aa testDetectsRemovalOfFieldArgument 2017-11-17 17:18:26 -05:00
Ben Roberts
cac011246e testDetectsValuesRemovedFromEnum 2017-11-17 16:24:04 -05:00
Ben Roberts
98ce1ccc69 testDetectsIfTypeWasRemovedFromUnion 2017-11-17 16:08:44 -05:00
Ben Roberts
dde2747918 testDetectsNonNullFieldAddedToInputType 2017-11-17 15:56:53 -05:00
Ben Roberts
cf4cccf4d6 testShouldDetectInputFieldChanges 2017-11-17 15:43:16 -05:00
Ben Roberts
68dbcc9ca3 testShouldDetectFieldChangesAndDeletions test 2017-11-17 14:29:47 -05:00
Ben Roberts
b2b5d6f080 findTypesThatChangedKind test 2017-11-17 13:04:01 -05:00
Ben Roberts
d9ce567cc8 findRemovedTypes test 2017-11-17 11:21:05 -05:00
Vladimir Razuvaev
b17b1c3336 Merge remote-tracking branch 'origin/master' 2017-10-14 00:45:55 +07:00
Vladimir Razuvaev
1487741f37 Preserve description for custom scalars (#181) 2017-10-14 00:45:23 +07:00
Gabriel Goncalves
440d38d3bc Creating test to Language\Token 2017-10-04 12:06:25 -03:00
Vladimir Razuvaev
f7248dec76 Ability to override internal types (using types option of Schema class) #174 2017-09-22 23:08:51 +07:00
Vladimir Razuvaev
1e34982bda Additional tests for variable coercion + use printSafeJson vs printSafe for input variables 2017-09-20 18:40:45 +07:00
Vladimir Razuvaev
a1e06b2e61 Account for query offset in files for errors 2017-09-20 18:36:19 +07:00
Vladimir Razuvaev
6050af4e67 Add support for directives applied on IDL & Schema 2017-09-20 17:43:06 +07:00
Vladimir Razuvaev
39f378ece7 Fixed type in tests: Testcase -> TestCase 2017-09-20 17:03:22 +07:00
Derek Lavigne
d22385cc93 Update query variable coercion to meet the rules outlined in the
specification.

The framework currently coerces query variables similar to the way it
treats output values, which means it attempts to coerce the value into
the field's corresponding data type regardless of the received value.
According to items 3f and 3g in section 6.1.2
(http://facebook.github.io/graphql/#sec-Validating-Requests) of
Facebook's GraphQL specification query variables should be coerced
according to their type's input coercion rules laid out in section
3.1.1 (http://facebook.github.io/graphql/#sec-Scalars). If the value
can not be coerced into the correct type according the the input
coercion rules for the type a query error should be thrown. This
ensures that client provided query variables were of the correct format
and will be a valid format and type by the time they are passed into an
implementing resolver.

This patch fixes the above issue by updating the way query variables
are sanitized during the process of parsing the query. It directly
follows the rules for scalar input coercion laid out by the
specification and throws query errors when a value that cannot be
coerced to the correct type is given. Tests for isValidPHPValue will
also be updated to ensure that it is doing the correct type checks on
Values::isValidPHPValue for the given type and value provided. A new
test case will also be added to test Values::getVariableValues and make
sure it is also enforcing the scalar input coercion rules and throwing
errors for invalid values.
2017-09-18 12:14:09 -04:00
Vladimir Razuvaev
6ff427d241 Server: do not raise an error when variables are passed as empty string (#156) 2017-08-30 23:26:45 +07:00
Vladimir Razuvaev
d95fb461ee Server: fixed constructor screwed during rebasing + restored tests for the server 2017-08-21 01:18:23 +07:00
Vladimir Razuvaev
90602b31ba Added link to docs for generic error about unique type instance (#149) 2017-08-20 22:28:17 +07:00
Vladimir Razuvaev
085516bdda Moved GraphQL\Language\AST\Node::fromArray to GraphQL\Utils\AST::fromArray 2017-08-20 19:50:44 +07:00
Vladimir Razuvaev
1b4f983f3f Improved docblock comments (suitable for reference docs generation) 2017-08-19 23:01:46 +07:00
Vladimir Razuvaev
203fddfe4e Abstract base class for validation rules 2017-08-18 20:56:04 +07:00
Vladimir Razuvaev
9499e5ae8e Suppressing Config deprecation warning in tests 2017-08-18 18:07:23 +07:00
Vladimir Razuvaev
83cc9132a0 Server: minor improvements 2017-08-18 02:54:35 +07:00
Vladimir Razuvaev
e52fe8c384 BuildSchema::build() now accepts DocumentNode as well 2017-08-17 20:33:36 +07:00
Vladimir Razuvaev
03629c1e3c Refactored error formatting (debugging part) 2017-08-17 18:49:17 +07:00
Vladimir Razuvaev
f369d4e2d4 Reverted unnecessary breaking change 2017-08-15 23:39:07 +07:00
Vladimir Razuvaev
3971001f6d Server: additional tests + related fixes 2017-08-15 20:59:48 +07:00
Vladimir Razuvaev
828c6b0fc3 Server: disable query batching by default; allow array as server config 2017-08-15 18:05:09 +07:00
Vladimir Razuvaev
9931cde6d4 Tests for lazy type loading during query execution + related changed 2017-08-15 01:49:56 +07:00
Vladimir Razuvaev
e4813c3a05 Additional checks and tests for situations when user-land code returns duplicate type instances 2017-08-14 23:52:17 +07:00
Vladimir Razuvaev
8817d54e83 Validate that type loader always returns the same type instance as referenced in other parts of the schema 2017-08-14 22:32:07 +07:00
Vladimir Razuvaev
b9d3a11785 Extracted lazy schema test; minor related refactoring 2017-08-14 20:41:08 +07:00
Vladimir Razuvaev
f47db61907 Fully load all schema types in constructor when type loader is not set 2017-08-14 19:44:16 +07:00
Vladimir Razuvaev
884a8967f3 Type loader tests 2017-08-14 19:42:01 +07:00
Vladimir Razuvaev
20f8cab943 Removed schema descriptor (as lazy loading of types can work without it now) 2017-08-14 01:42:02 +07:00
Vladimir Razuvaev
f9eb14869f Removed callbacks in field types (previously deprecated in #35) 2017-08-14 00:50:24 +07:00
Vladimir Razuvaev
6845b28a35 Deprecated GraphQL\Type\Definition\Config (#148) 2017-08-14 00:09:02 +07:00
Vladimir Razuvaev
ed3591c1a9 Fixed broken build 2017-08-13 23:24:23 +07:00
Vladimir Razuvaev
34eae0b891 Schema validation + tests (#148) 2017-08-13 23:04:03 +07:00
Vladimir Razuvaev
f911fac7b1 Default error reporting now includes "category" key for every error 2017-08-08 02:02:07 +07:00
Vladimir Razuvaev
09070485c1 Added ability to decorate type configs in BuildSchema + made type creation lazy 2017-07-28 17:55:25 +07:00
Vladimir Razuvaev
1af902865b AST: new NodeList class for collections of nodes (vs array) to enable effective conversion of libgraphqlparser output to our AST tree 2017-07-21 22:29:59 +07:00
Vladimir Razuvaev
e04d3300a7 Server: send result for regular responses + prepare response for PSR7 request 2017-07-21 22:11:20 +07:00
Vladimir Razuvaev
e6e531b88b Server: throw only when there is a configuration or logic error (invariant violation) 2017-07-19 19:30:39 +07:00
Vladimir Razuvaev
38922dbbed Default error formatter now returns "Internal server error" unless error is client-aware and safe to report directly to end-users 2017-07-18 20:57:30 +07:00
Vladimir Razuvaev
8e3d1eb29b Merge branch 'master' of https://github.com/webonyx/graphql-php into v0.10 2017-07-18 00:42:52 +07:00
Vladimir Razuvaev
8fe26a1a21 String and ID types should not try to convert non-scalar values to string (#121) 2017-07-18 00:25:45 +07:00
Vladimir Razuvaev
919cf80240 Server: batched queries with shared deferreds (promises) #105 2017-07-17 20:31:26 +07:00
Vladimir Razuvaev
0e2ac57515 Split HTTP server execution to canonical replaceable steps: parsing, validation, execution with separate tests for each step 2017-07-17 16:57:30 +07:00
Vladimir Razuvaev
f8c3195e54 Granular methods for HTTP request parsing + tests 2017-07-16 19:04:58 +07:00
Vladimir Razuvaev
d2cbb0c354 Restored tests for deprecated GraphQL\Server 2017-07-14 20:06:24 +07:00
Vladimir Razuvaev
794d3672ef Initial pass on standard server implementation (also deprecated current GraphQL\Server which is undocumented anyway) 2017-07-14 19:44:18 +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
aaa5b7af41 Global config; descriptor moved to appropriate namespace; minor cleanup 2017-07-12 13:16:34 +07:00
Vladimir Razuvaev
296544089c Moved GraphQL\Utils to GraphQL\Utils\Utils 2017-07-10 19:53:46 +07:00
Vladimir Razuvaev
ed28deda81 Replaced trigger_error with Warning for resolveType warning 2017-07-10 19:38:12 +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
463d995d95 Reverted #116 (now Executor::defaultFieldResolver checks for instanceof Closure vs is_callable again) 2017-07-08 15:22:17 +07:00
Vladimir Razuvaev
3beeb06340 Merge branches 'master' and 'v0.10' of https://github.com/webonyx/graphql-php into v0.10
# Conflicts:
#	src/Utils/MixedStore.php
2017-07-06 19:50:23 +07:00