graphql-php/tests/Executor/VariablesTest.php

826 lines
27 KiB
PHP
Raw Normal View History

2015-07-15 20:05:46 +03:00
<?php
2016-04-09 10:36:53 +03:00
namespace GraphQL\Tests\Executor;
2015-07-15 20:05:46 +03:00
require_once __DIR__ . '/TestClasses.php';
use GraphQL\Error\Error;
2016-04-09 10:36:53 +03:00
use GraphQL\Executor\Executor;
use GraphQL\Error\FormattedError;
2015-07-15 20:05:46 +03:00
use GraphQL\Language\Parser;
use GraphQL\Language\SourceLocation;
use GraphQL\Schema;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
class VariablesTest extends \PHPUnit_Framework_TestCase
2015-07-15 20:05:46 +03:00
{
// Execute: Handles inputs
2015-07-15 20:05:46 +03:00
// Handles objects and nullability
/**
* @describe using inline structs
*/
2015-07-15 20:05:46 +03:00
public function testUsingInlineStructs()
{
// executes with complex input:
$doc = '
{
fieldWithObjectInput(input: {a: "foo", b: ["bar"], c: "baz"})
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}'
]
];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
// properly parses single value to list:
2015-07-15 20:05:46 +03:00
$doc = '
{
fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
// does not use incorrect value
$doc = '
{
fieldWithObjectInput(input: ["foo", "bar", "baz"])
}
';
$ast = Parser::parse($doc);
$result = Executor::execute($this->schema(), $ast)->toArray();
$expected = [
'data' => ['fieldWithObjectInput' => null]
];
$this->assertEquals($expected, $result);
// properly runs parseLiteral on complex scalar types
$doc = '
{
fieldWithObjectInput(input: {a: "foo", d: "SerializedValue"})
}
';
$ast = Parser::parse($doc);
$this->assertEquals(
['data' => ['fieldWithObjectInput' => '{"a":"foo","d":"DeserializedValue"}']],
Executor::execute($this->schema(), $ast)->toArray()
);
2015-07-15 20:05:46 +03:00
}
/**
* @describe using variables
*/
2015-07-15 20:05:46 +03:00
public function testUsingVariables()
{
// executes with complex input:
$doc = '
query q($input:TestInputObject) {
fieldWithObjectInput(input: $input)
}
';
$ast = Parser::parse($doc);
$params = ['input' => ['a' => 'foo', 'b' => ['bar'], 'c' => 'baz']];
$schema = $this->schema();
$this->assertEquals(
['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']],
Executor::execute($schema, $ast, null, null, $params)->toArray()
2015-07-15 20:05:46 +03:00
);
// uses default value when not provided:
$withDefaultsAST = Parser::parse('
query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
fieldWithObjectInput(input: $input)
}
');
$result = Executor::execute($this->schema(), $withDefaultsAST)->toArray();
$expected = [
'data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']
];
$this->assertEquals($expected, $result);
// properly parses single value to array:
2015-07-15 20:05:46 +03:00
$params = ['input' => ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']];
$this->assertEquals(
['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']],
Executor::execute($schema, $ast, null, null, $params)->toArray()
2015-07-15 20:05:46 +03:00
);
// executes with complex scalar input:
$params = [ 'input' => [ 'c' => 'foo', 'd' => 'SerializedValue' ] ];
$result = Executor::execute($schema, $ast, null, null, $params)->toArray();
2015-07-15 20:05:46 +03:00
$expected = [
'data' => [
'fieldWithObjectInput' => '{"c":"foo","d":"DeserializedValue"}'
]
2015-07-15 20:05:46 +03:00
];
$this->assertEquals($expected, $result);
// errors on null for nested non-null:
$params = ['input' => ['a' => 'foo', 'b' => 'bar', 'c' => null]];
$expected = FormattedError::create(
'Variable "$input" got invalid value {"a":"foo","b":"bar","c":null}.'. "\n".
'In field "c": Expected "String!", found null.',
[new SourceLocation(2, 17)]
);
2015-07-15 20:05:46 +03:00
try {
Executor::execute($schema, $ast, null, null, $params);
$this->fail('Expected exception not thrown');
} catch (Error $err) {
$this->assertEquals($expected, Error::formatError($err));
}
// errors on incorrect type:
$params = [ 'input' => 'foo bar' ];
try {
Executor::execute($schema, $ast, null, null, $params);
$this->fail('Expected exception not thrown');
} catch (Error $error) {
$expected = FormattedError::create(
'Variable "$input" got invalid value "foo bar".'."\n".
'Expected "TestInputObject", found not an object.',
[new SourceLocation(2, 17)]
);
$this->assertEquals($expected, Error::formatError($error));
}
2015-07-15 20:05:46 +03:00
// errors on omission of nested non-null:
$params = ['input' => ['a' => 'foo', 'b' => 'bar']];
try {
Executor::execute($schema, $ast, null, null, $params);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$expected = FormattedError::create(
'Variable "$input" got invalid value {"a":"foo","b":"bar"}.'. "\n".
'In field "c": Expected "String!", found null.',
[new SourceLocation(2, 17)]
);
$this->assertEquals($expected, Error::formatError($e));
}
// errors on deep nested errors and with many errors
$nestedDoc = '
query q($input: TestNestedInputObject) {
fieldWithNestedObjectInput(input: $input)
}
';
$nestedAst = Parser::parse($nestedDoc);
$params = [ 'input' => [ 'na' => [ 'a' => 'foo' ] ] ];
try {
Executor::execute($schema, $nestedAst, null, null, $params);
$this->fail('Expected exception not thrown');
} catch (Error $error) {
$expected = FormattedError::create(
'Variable "$input" got invalid value {"na":{"a":"foo"}}.' . "\n" .
'In field "na": In field "c": Expected "String!", found null.' . "\n" .
'In field "nb": Expected "String!", found null.',
[new SourceLocation(2, 19)]
);
$this->assertEquals($expected, Error::formatError($error));
}
// errors on addition of unknown input field
$params = ['input' => [ 'a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'dog' ]];
try {
Executor::execute($schema, $ast, null, null, $params);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$expected = FormattedError::create(
'Variable "$input" got invalid value {"a":"foo","b":"bar","c":"baz","d":"dog"}.'."\n".
'In field "d": Expected type "ComplexScalar", found "dog".',
[new SourceLocation(2, 17)]
);
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
// Describe: Handles nullable scalars
2015-07-15 20:05:46 +03:00
/**
* @it allows nullable inputs to be omitted
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeOmitted()
{
$doc = '
{
fieldWithNullableStringInput
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => ['fieldWithNullableStringInput' => null]
2015-07-15 20:05:46 +03:00
];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows nullable inputs to be omitted in a variable
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeOmittedInAVariable()
{
$doc = '
query SetsNullable($value: String) {
fieldWithNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
2015-07-15 20:05:46 +03:00
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows nullable inputs to be omitted in an unlisted variable
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeOmittedInAnUnlistedVariable()
{
$doc = '
query SetsNullable {
fieldWithNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows nullable inputs to be set to null in a variable
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeSetToNullInAVariable()
{
$doc = '
query SetsNullable($value: String) {
fieldWithNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
2015-07-15 20:05:46 +03:00
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, ['value' => null])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows nullable inputs to be set to a value in a variable
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeSetToAValueInAVariable()
{
$doc = '
query SetsNullable($value: String) {
fieldWithNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNullableStringInput' => '"a"']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['value' => 'a'])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows nullable inputs to be set to a value directly
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNullableInputsToBeSetToAValueDirectly()
{
$doc = '
{
fieldWithNullableStringInput(input: "a")
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNullableStringInput' => '"a"']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
// Describe: Handles non-nullable scalars
/**
* @it does not allow non-nullable inputs to be omitted in a variable
*/
2015-07-15 20:05:46 +03:00
public function testDoesntAllowNonNullableInputsToBeOmittedInAVariable()
{
$doc = '
query SetsNonNullable($value: String!) {
fieldWithNonNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
try {
Executor::execute($this->schema(), $ast);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$expected = FormattedError::create(
'Variable "$value" of required type "String!" was not provided.',
[new SourceLocation(2, 31)]
);
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow non-nullable inputs to be set to null in a variable
*/
2015-07-15 20:05:46 +03:00
public function testDoesNotAllowNonNullableInputsToBeSetToNullInAVariable()
{
$doc = '
query SetsNonNullable($value: String!) {
fieldWithNonNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
try {
Executor::execute($this->schema(), $ast, null, ['value' => null]);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$expected = FormattedError::create(
'Variable "$value" of required type "String!" was not provided.',
[new SourceLocation(2, 31)]
);
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it allows non-nullable inputs to be set to a value in a variable
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNonNullableInputsToBeSetToAValueInAVariable()
{
$doc = '
query SetsNonNullable($value: String!) {
fieldWithNonNullableStringInput(input: $value)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNonNullableStringInput' => '"a"']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['value' => 'a'])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows non-nullable inputs to be set to a value directly
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNonNullableInputsToBeSetToAValueDirectly()
{
$doc = '
{
fieldWithNonNullableStringInput(input: "a")
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNonNullableStringInput' => '"a"']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it passes along null for non-nullable inputs if explcitly set in the query
*/
2015-07-15 20:05:46 +03:00
public function testPassesAlongNullForNonNullableInputsIfExplcitlySetInTheQuery()
{
$doc = '
{
fieldWithNonNullableStringInput
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithNonNullableStringInput' => null]];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
2015-07-15 20:05:46 +03:00
}
// Describe: Handles lists and nullability
/**
* @it allows lists to be null
*/
2015-07-15 20:05:46 +03:00
public function testAllowsListsToBeNull()
{
$doc = '
query q($input:[String]) {
list(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['list' => null]];
2015-07-15 20:05:46 +03:00
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, ['input' => null])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows lists to contain values
*/
2015-07-15 20:05:46 +03:00
public function testAllowsListsToContainValues()
{
$doc = '
query q($input:[String]) {
list(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['list' => '["A"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => ['A']])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows lists to contain null
*/
2015-07-15 20:05:46 +03:00
public function testAllowsListsToContainNull()
{
$doc = '
query q($input:[String]) {
list(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['list' => '["A",null,"B"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => ['A',null,'B']])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow non-null lists to be null
*/
2015-07-15 20:05:46 +03:00
public function testDoesNotAllowNonNullListsToBeNull()
{
$doc = '
query q($input:[String]!) {
nnList(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = FormattedError::create(
'Variable "$input" of required type "[String]!" was not provided.',
[new SourceLocation(2, 17)]
);
2015-07-15 20:05:46 +03:00
try {
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => null])->toArray());
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it allows non-null lists to contain values
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNonNullListsToContainValues()
{
$doc = '
query q($input:[String]!) {
nnList(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['nnList' => '["A"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => 'A'])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows non-null lists to contain null
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNonNullListsToContainNull()
{
$doc = '
query q($input:[String]!) {
nnList(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['nnList' => '["A",null,"B"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => ['A',null,'B']])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows lists of non-nulls to be null
*/
2015-07-15 20:05:46 +03:00
public function testAllowsListsOfNonNullsToBeNull()
{
$doc = '
query q($input:[String!]) {
listNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['listNN' => null]];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, ['input' => null])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it allows lists of non-nulls to contain values
*/
2015-07-15 20:05:46 +03:00
public function testAllowsListsOfNonNullsToContainValues()
{
$doc = '
query q($input:[String!]) {
listNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['listNN' => '["A"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => 'A'])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow lists of non-nulls to contain null
*/
2015-07-15 20:05:46 +03:00
public function testDoesNotAllowListsOfNonNullsToContainNull()
{
$doc = '
query q($input:[String!]) {
listNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = FormattedError::create(
'Variable "$input" got invalid value ["A",null,"B"].' . "\n" .
'In element #1: Expected "String!", found null.',
[new SourceLocation(2, 17)]
);
try {
Executor::execute($this->schema(), $ast, null, null, ['input' => ['A', null, 'B']]);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow non-null lists of non-nulls to be null
*/
2015-07-15 20:05:46 +03:00
public function testDoesNotAllowNonNullListsOfNonNullsToBeNull()
{
$doc = '
query q($input:[String!]!) {
nnListNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = FormattedError::create(
'Variable "$input" of required type "[String!]!" was not provided.',
[new SourceLocation(2, 17)]
);
try {
Executor::execute($this->schema(), $ast, null, null, ['input' => null]);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it allows non-null lists of non-nulls to contain values
*/
2015-07-15 20:05:46 +03:00
public function testAllowsNonNullListsOfNonNullsToContainValues()
{
$doc = '
query q($input:[String!]!) {
nnListNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['nnListNN' => '["A"]']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, ['input' => ['A']])->toArray());
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow non-null lists of non-nulls to contain null
*/
2015-07-15 20:05:46 +03:00
public function testDoesNotAllowNonNullListsOfNonNullsToContainNull()
{
$doc = '
query q($input:[String!]!) {
nnListNN(input: $input)
}
';
$ast = Parser::parse($doc);
$expected = FormattedError::create(
'Variable "$input" got invalid value ["A",null,"B"].'."\n".
'In element #1: Expected "String!", found null.',
[new SourceLocation(2, 17)]
);
try {
Executor::execute($this->schema(), $ast, null, null, ['input' => ['A', null, 'B']]);
$this->fail('Expected exception not thrown');
} catch (Error $e) {
$this->assertEquals($expected, Error::formatError($e));
}
2015-07-15 20:05:46 +03:00
}
/**
* @it does not allow invalid types to be used as values
*/
public function testDoesNotAllowInvalidTypesToBeUsedAsValues()
{
$doc = '
query q($input: TestType!) {
fieldWithObjectInput(input: $input)
}
';
$ast = Parser::parse($doc);
$vars = [ 'input' => [ 'list' => [ 'A', 'B' ] ] ];
try {
Executor::execute($this->schema(), $ast, null, null, $vars);
$this->fail('Expected exception not thrown');
} catch (Error $error) {
$expected = FormattedError::create(
'Variable "$input" expected value of type "TestType!" which cannot ' .
'be used as an input type.',
[new SourceLocation(2, 17)]
);
$this->assertEquals($expected, Error::formatError($error));
}
}
/**
* @it does not allow unknown types to be used as values
*/
public function testDoesNotAllowUnknownTypesToBeUsedAsValues()
{
$doc = '
query q($input: UnknownType!) {
fieldWithObjectInput(input: $input)
}
';
$ast = Parser::parse($doc);
$vars = ['input' => 'whoknows'];
try {
Executor::execute($this->schema(), $ast, null, null, $vars);
$this->fail('Expected exception not thrown');
} catch (Error $error) {
$expected = FormattedError::create(
'Variable "$input" expected value of type "UnknownType!" which ' .
'cannot be used as an input type.',
[new SourceLocation(2, 17)]
);
$this->assertEquals($expected, Error::formatError($error));
}
}
// Describe: Execute: Uses argument default values
/**
* @it when no argument provided
*/
public function testWhenNoArgumentProvided()
{
$ast = Parser::parse('{
fieldWithDefaultArgumentValue
}');
$this->assertEquals(
['data' => ['fieldWithDefaultArgumentValue' => '"Hello World"']],
Executor::execute($this->schema(), $ast)->toArray()
);
}
/**
* @it when nullable variable provided
*/
public function testWhenNullableVariableProvided()
{
$ast = Parser::parse('query optionalVariable($optional: String) {
fieldWithDefaultArgumentValue(input: $optional)
}');
$this->assertEquals(
['data' => ['fieldWithDefaultArgumentValue' => '"Hello World"']],
Executor::execute($this->schema(), $ast)->toArray()
);
}
/**
* @it when argument provided cannot be parsed
*/
public function testWhenArgumentProvidedCannotBeParsed()
{
$ast = Parser::parse('{
fieldWithDefaultArgumentValue(input: WRONG_TYPE)
}');
$this->assertEquals(
['data' => ['fieldWithDefaultArgumentValue' => '"Hello World"']],
Executor::execute($this->schema(), $ast)->toArray()
);
}
2015-07-15 20:05:46 +03:00
public function schema()
{
$ComplexScalarType = ComplexScalar::create();
2015-07-15 20:05:46 +03:00
$TestInputObject = new InputObjectType([
'name' => 'TestInputObject',
'fields' => [
'a' => ['type' => Type::string()],
'b' => ['type' => Type::listOf(Type::string())],
'c' => ['type' => Type::nonNull(Type::string())],
'd' => ['type' => $ComplexScalarType],
2015-07-15 20:05:46 +03:00
]
]);
$TestNestedInputObject = new InputObjectType([
'name' => 'TestNestedInputObject',
'fields' => [
'na' => [ 'type' => Type::nonNull($TestInputObject) ],
'nb' => [ 'type' => Type::nonNull(Type::string()) ],
],
]);
2015-07-15 20:05:46 +03:00
$TestType = new ObjectType([
'name' => 'TestType',
'fields' => [
'fieldWithObjectInput' => [
'type' => Type::string(),
'args' => ['input' => ['type' => $TestInputObject]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'fieldWithNullableStringInput' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::string()]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'fieldWithNonNullableStringInput' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::nonNull(Type::string())]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
}
],
'fieldWithDefaultArgumentValue' => [
'type' => Type::string(),
'args' => [ 'input' => [ 'type' => Type::string(), 'defaultValue' => 'Hello World' ]],
'resolve' => function($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'fieldWithNestedInputObject' => [
'type' => Type::string(),
'args' => [
'input' => [
'type' => $TestNestedInputObject,
'defaultValue' => 'Hello World'
]
],
'resolve' => function($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
}
],
2015-07-15 20:05:46 +03:00
'list' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::listOf(Type::string())]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'nnList' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::string()))]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'listNN' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::listOf(Type::nonNull(Type::string()))]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
'nnListNN' => [
'type' => Type::string(),
'args' => ['input' => ['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string())))]],
'resolve' => function ($_, $args) {
return isset($args['input']) ? json_encode($args['input']) : null;
2015-07-15 20:05:46 +03:00
}
],
]
]);
$schema = new Schema(['query' => $TestType]);
2015-07-15 20:05:46 +03:00
return $schema;
}
}