Commit Graph

51 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Adrien Crivelli
5cbaf973e1
Leverage PHPUnit setExpectedException() instead of custom code
Closes #219
2018-01-01 18:06:08 +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
1487741f37 Preserve description for custom scalars (#181) 2017-10-14 00:45:23 +07:00
Vladimir Razuvaev
6050af4e67 Add support for directives applied on IDL & Schema 2017-09-20 17:43:06 +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
e52fe8c384 BuildSchema::build() now accepts DocumentNode as well 2017-08-17 20:33:36 +07:00
Vladimir Razuvaev
6845b28a35 Deprecated GraphQL\Type\Definition\Config (#148) 2017-08-14 00:09:02 +07:00
Vladimir Razuvaev
34eae0b891 Schema validation + tests (#148) 2017-08-13 23:04:03 +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
296544089c Moved GraphQL\Utils to GraphQL\Utils\Utils 2017-07-10 19:53:46 +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
Vladimir Razuvaev
bc6a7a3d1d Fix: allow MixedStore to accept true, false, null and floats as keys + related tests 2017-07-06 19:29:33 +07:00
Vladimir Razuvaev
24bcc65314 SchemaPrinter: reverted sorting of fields in printed version (as it breaks s = parse(print(s)) rule) 2017-07-05 19:45:02 +07:00
Vladimir Razuvaev
0b7d55c30d SchemaPrinter: sort fields before printing to get more stable diff 2017-07-05 18:33:16 +07:00
Vladimir Razuvaev
b47c87f793 Allow null values for enums 2017-07-04 20:19:52 +07:00
Vladimir Razuvaev
f569c6de2d Spec compliance: coercion of Int values 2017-07-04 18:27:20 +07:00
Vladimir Razuvaev
76e182e616 Forbid duplicate type definitions 2017-07-04 14:01:00 +07:00
Vladimir Razuvaev
3f909e3e11 Separate utility for extractTypes 2017-02-24 16:29:28 +07:00
petecoop
fc629a292d BuildSchema and SchemaPrinter 2017-02-19 19:26:56 +00:00
vladar
8d696edee5 Renamed AST nodes to *Node to disambiguate types 2016-11-19 06:12:18 +07:00
vladar
439959b292 Enforce input coercion rules 2016-11-19 04:15:40 +07:00
vladar
8a676cde99 Support for NullValue 2016-11-18 23:59:28 +07:00
vladar
3b0e52f254 Updated AST Utils to match the behavior of reference implementation 2016-11-02 00:11:33 +07:00