public function testEvaluatesMutationsCorrectlyInThePresenseOfAFailedMutation() { $doc = 'mutation M { first: immediatelyChangeTheNumber(newNumber: 1) { theNumber }, second: promiseToChangeTheNumber(newNumber: 2) { theNumber }, third: failToChangeTheNumber(newNumber: 3) { theNumber } fourth: promiseToChangeTheNumber(newNumber: 4) { theNumber }, fifth: immediatelyChangeTheNumber(newNumber: 5) { theNumber } sixth: promiseAndFailToChangeTheNumber(newNumber: 6) { theNumber } }'; $ast = Parser::parse($doc); $mutationResult = Executor::execute($this->schema(), $ast, new Root(6), null, 'M'); $expected = ['data' => ['first' => ['theNumber' => 1], 'second' => ['theNumber' => 2], 'third' => null, 'fourth' => ['theNumber' => 4], 'fifth' => ['theNumber' => 5], 'sixth' => null], 'errors' => [FormattedError::create('Cannot change the number', [new SourceLocation(8, 7)]), FormattedError::create('Cannot change the number', [new SourceLocation(17, 7)])]]; $this->assertEquals($expected, $mutationResult->toArray()); }
public function testOutputTypesAreInvalid() { $this->expectFailsRule(new VariablesAreInputTypes(), ' query Foo($a: Dog, $b: [[CatOrDog!]]!, $c: Pet) { field(a: $a, b: $b, c: $c) } ', [FormattedError::create(VariablesAreInputTypes::nonInputTypeOnVarMessage('a', 'Dog'), [new SourceLocation(2, 21)]), FormattedError::create(VariablesAreInputTypes::nonInputTypeOnVarMessage('b', '[[CatOrDog!]]!'), [new SourceLocation(2, 30)]), FormattedError::create(VariablesAreInputTypes::nonInputTypeOnVarMessage('c', 'Pet'), [new SourceLocation(2, 50)])]); }
private function undefVarByOp($varName, $l1, $c1, $opName, $l2, $c2) { return FormattedError::create(NoUndefinedVariables::undefinedVarByOpMessage($varName, $opName), [new SourceLocation($l1, $c1), new SourceLocation($l2, $c2)]); }
function badValue($argName, $typeName, $value, $line, $column) { return FormattedError::create(ArgumentsOfCorrectType::badValueMessage($argName, $typeName, $value), [new SourceLocation($line, $column)]); }
public function testNullsTheTopLevelIfSyncNonNullableFieldReturnsNull() { // nulls the top level if sync non-nullable field returns null $doc = ' query Q { nonNullSync } '; $expected = ['data' => null, 'errors' => [FormattedError::create('Cannot return null for non-nullable type.', [new SourceLocation(2, 17)])]]; $this->assertEquals($expected, Executor::execute($this->schema, Parser::parse($doc), $this->nullingData)->toArray()); }
public function testStringXBooleanNonNullInDirective() { // String => Boolean! in directive $this->expectFailsRule(new VariablesInAllowedPosition(), ' query Query($stringVar: String) { dog @include(if: $stringVar) } ', [FormattedError::create(Messages::badVarPosMessage('stringVar', 'String', 'Boolean!'), [new SourceLocation(4, 26)])]); }
private function undefFrag($fragName, $line, $column) { return FormattedError::create(KnownFragmentNames::unknownFragmentMessage($fragName), [new SourceLocation($line, $column)]); }
public function testNullsOutErrorSubtrees() { $doc = '{ sync, syncError, syncRawError, async, asyncReject, asyncError }'; $data = ['sync' => function () { return 'sync'; }, 'syncError' => function () { throw new Error('Error getting syncError'); }, 'syncRawError' => function () { throw new \Exception('Error getting syncRawError'); }, 'async' => function () { return 'async'; }, 'asyncReject' => function () { throw new \Exception('Error getting asyncReject'); }, 'asyncError' => function () { throw new \Exception('Error getting asyncError'); }]; $docAst = Parser::parse($doc); $schema = new Schema(new ObjectType(['name' => 'Type', 'fields' => ['sync' => ['type' => Type::string()], 'syncError' => ['type' => Type::string()], 'syncRawError' => ['type' => Type::string()], 'async' => ['type' => Type::string()], 'asyncReject' => ['type' => Type::string()], 'asyncError' => ['type' => Type::string()]]])); $expected = ['data' => ['sync' => 'sync', 'syncError' => null, 'syncRawError' => null, 'async' => 'async', 'asyncReject' => null, 'asyncError' => null], 'errors' => [FormattedError::create('Error getting syncError', [new SourceLocation(3, 7)]), FormattedError::create('Error getting syncRawError', [new SourceLocation(4, 7)]), FormattedError::create('Error getting asyncReject', [new SourceLocation(6, 7)]), FormattedError::create('Error getting asyncError', [new SourceLocation(7, 7)])]]; $result = Executor::execute($schema, $docAst, $data); $this->assertEquals($expected, $result->toArray()); }
private function errorAnon($parentType, $fragType, $line, $column) { return FormattedError::create(PossibleFragmentSpreads::typeIncompatibleAnonSpreadMessage($parentType, $fragType), [new SourceLocation($line, $column)]); }
public function testDoesNotAllowNonNullListsOfNonNullsToContainNull() { $doc = ' query q($input:[String!]!) { nnListNN(input: $input) } '; $ast = Parser::parse($doc); $expected = FormattedError::create('Variable $input expected value of type [String!]! but got: ["A",null,"B"].', [new SourceLocation(2, 17)]); try { Executor::execute($this->schema(), $ast, null, ['input' => ['A', null, 'B']]); } catch (Error $e) { $this->assertEquals($expected, Error::formatError($e)); } }
private function undefinedField($field, $type, $line, $column) { return FormattedError::create(Messages::undefinedFieldMessage($field, $type), [new SourceLocation($line, $column)]); }
private function badValue($varName, $typeName, $val, $line, $column) { return FormattedError::create(Messages::badValueForDefaultArgMessage($varName, $typeName, $val), [new SourceLocation($line, $column)]); }
function misplacedDirective($directiveName, $placement, $line, $column) { return FormattedError::create(KnownDirectives::misplacedDirectiveMessage($directiveName, $placement), [new SourceLocation($line, $column)]); }
private function unusedFrag($fragName, $line, $column) { return FormattedError::create(NoUnusedFragments::unusedFragMessage($fragName), [new SourceLocation($line, $column)]); }
public function testHandlesNonNullListsOfNonNullsWhenTheyReturnNull() { $doc = ' query Q { nest { nonNullListOfNonNullReturnsNull, } } '; $ast = Parser::parse($doc); $expected = ['data' => ['nest' => null], 'errors' => [FormattedError::create('Cannot return null for non-nullable type.', [new SourceLocation(4, 11)])]]; $this->assertEquals($expected, Executor::execute($this->schema(), $ast, $this->data(), [], 'Q')->toArray()); }
private function error($fragName, $typeName, $line, $column) { return FormattedError::create(FragmentsOnCompositeTypes::fragmentOnNonCompositeErrorMessage($fragName, $typeName), [new SourceLocation($line, $column)]); }
private function missingObjSubselection($field, $type, $line, $column) { return FormattedError::create(ScalarLeafs::requiredSubselectionMessage($field, $type), [new SourceLocation($line, $column)]); }
public function testComparesDeepTypesIncludingList() { $this->expectFailsRuleWithSchema($this->getTestSchema(), new OverlappingFieldsCanBeMerged(), ' { connection { ...edgeID edges { node { id: name } } } } fragment edgeID on Connection { edges { node { id } } } ', [FormattedError::create(OverlappingFieldsCanBeMerged::fieldsConflictMessage('edges', [['node', [['id', 'id and name are different fields']]]]), [new SourceLocation(14, 11), new SourceLocation(5, 13), new SourceLocation(15, 13), new SourceLocation(6, 15), new SourceLocation(16, 15), new SourceLocation(7, 17)])]); }
private function cycleError($fargment, $spreadNames, $line, $column) { return FormattedError::create(NoFragmentCycles::cycleErrorMessage($fargment, $spreadNames), [new SourceLocation($line, $column)]); }
private function unknownDirectiveArg($argName, $directiveName, $line, $column) { return FormattedError::create(KnownArgumentNames::unknownDirectiveArgMessage($argName, $directiveName), [new SourceLocation($line, $column)]); }
/** * @param Error $error * @return array */ public static function formatError(Error $error) { return FormattedError::create($error->getMessage(), $error->getLocations()); }
public function testFailsAsExpectedOnThe__typeRootFieldWithoutAnArg() { $TestType = new ObjectType(['name' => 'TestType', 'fields' => ['testField' => ['type' => Type::string()]]]); $schema = new Schema($TestType); $request = ' { __type { name } } '; $expected = ['data' => null, 'errors' => [FormattedError::create(ProvidedNonNullArguments::missingFieldArgMessage('__type', 'name', 'String!'), [new SourceLocation(3, 9)])]]; $this->assertEquals($expected, GraphQL::execute($schema, $request)); }
private function unknownType($typeName, $line, $column) { return FormattedError::create(KnownTypeNames::unknownTypeMessage($typeName), [new SourceLocation($line, $column)]); }
private function unusedVar($varName, $line, $column) { return FormattedError::create(NoUnusedVariables::unusedVariableMessage($varName), [new SourceLocation($line, $column)]); }
private function missingDirectiveArg($directiveName, $argName, $typeName, $line, $column) { return FormattedError::create(ProvidedNonNullArguments::missingDirectiveArgMessage($directiveName, $argName, $typeName), [new SourceLocation($line, $column)]); }