mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-03-12 15:56:06 +03:00
Fully load all schema types in constructor when type loader is not set
This commit is contained in:
parent
884a8967f3
commit
f47db61907
@ -226,6 +226,20 @@ EOD;
|
|||||||
return $includeDescription ? $withDescription : $withoutDescription;
|
return $includeDescription ? $withDescription : $withoutDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTypes()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'__Schema' => self::_schema(),
|
||||||
|
'__Type' => self::_type(),
|
||||||
|
'__Directive' => self::_directive(),
|
||||||
|
'__Field' => self::_field(),
|
||||||
|
'__InputValue' => self::_inputValue(),
|
||||||
|
'__EnumValue' => self::_enumValue(),
|
||||||
|
'__TypeKind' => self::_typeKind(),
|
||||||
|
'__DirectiveLocation' => self::_directiveLocation(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public static function _schema()
|
public static function _schema()
|
||||||
{
|
{
|
||||||
if (!isset(self::$map['__Schema'])) {
|
if (!isset(self::$map['__Schema'])) {
|
||||||
|
@ -122,6 +122,9 @@ class Schema
|
|||||||
if ($config->subscription) {
|
if ($config->subscription) {
|
||||||
$this->resolvedTypes[$config->subscription->name] = $config->subscription;
|
$this->resolvedTypes[$config->subscription->name] = $config->subscription;
|
||||||
}
|
}
|
||||||
|
if (!$this->config->typeLoader) {
|
||||||
|
$this->getTypeMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +57,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
$options['query'] instanceof ObjectType,
|
$options['query'] instanceof ObjectType,
|
||||||
'Schema query must be Object Type if provided but got: %s',
|
'Schema query must be Object Type if provided but got: %s',
|
||||||
Utils::getVariableType($options['query'])
|
Utils::printSafe($options['query'])
|
||||||
);
|
);
|
||||||
$config->setQuery($options['query']);
|
$config->setQuery($options['query']);
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
$options['mutation'] instanceof ObjectType,
|
$options['mutation'] instanceof ObjectType,
|
||||||
'Schema mutation must be Object Type if provided but got: %s',
|
'Schema mutation must be Object Type if provided but got: %s',
|
||||||
Utils::getVariableType($options['mutation'])
|
Utils::printSafe($options['mutation'])
|
||||||
);
|
);
|
||||||
$config->setMutation($options['mutation']);
|
$config->setMutation($options['mutation']);
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
$options['subscription'] instanceof ObjectType,
|
$options['subscription'] instanceof ObjectType,
|
||||||
'Schema subscription must be Object Type if provided but got: %s',
|
'Schema subscription must be Object Type if provided but got: %s',
|
||||||
Utils::getVariableType($options['subscription'])
|
Utils::printSafe($options['subscription'])
|
||||||
);
|
);
|
||||||
$config->setSubscription($options['subscription']);
|
$config->setSubscription($options['subscription']);
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
is_array($options['types']) || is_callable($options['types']),
|
is_array($options['types']) || is_callable($options['types']),
|
||||||
'Schema types must be array or callable if provided but got: %s',
|
'Schema types must be array or callable if provided but got: %s',
|
||||||
Utils::getVariableType($options['types'])
|
Utils::printSafe($options['types'])
|
||||||
);
|
);
|
||||||
$config->setTypes($options['types']);
|
$config->setTypes($options['types']);
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
is_array($options['directives']),
|
is_array($options['directives']),
|
||||||
'Schema directives must be array if provided but got: %s',
|
'Schema directives must be array if provided but got: %s',
|
||||||
Utils::getVariableType($options['directives'])
|
Utils::printSafe($options['directives'])
|
||||||
);
|
);
|
||||||
$config->setDirectives($options['directives']);
|
$config->setDirectives($options['directives']);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ class SchemaConfig
|
|||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
is_callable($options['typeLoader']),
|
is_callable($options['typeLoader']),
|
||||||
'Schema type loader must be callable if provided but got: %s',
|
'Schema type loader must be callable if provided but got: %s',
|
||||||
Utils::getVariableType($options['typeLoader'])
|
Utils::printSafe($options['typeLoader'])
|
||||||
);
|
);
|
||||||
$config->setTypeLoader($options['typeLoader']);
|
$config->setTypeLoader($options['typeLoader']);
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ class SchemaConfig
|
|||||||
*/
|
*/
|
||||||
public function getTypes()
|
public function getTypes()
|
||||||
{
|
{
|
||||||
return $this->types;
|
return $this->types ?: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,18 +32,18 @@ class StarWarsIntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
['name' => 'String'],
|
['name' => 'String'],
|
||||||
['name' => 'Human'],
|
['name' => 'Human'],
|
||||||
['name' => 'Droid'],
|
['name' => 'Droid'],
|
||||||
|
['name' => 'ID'],
|
||||||
|
['name' => 'Float'],
|
||||||
|
['name' => 'Int'],
|
||||||
|
['name' => 'Boolean'],
|
||||||
['name' => '__Schema'],
|
['name' => '__Schema'],
|
||||||
['name' => '__Type'],
|
['name' => '__Type'],
|
||||||
['name' => '__TypeKind'],
|
['name' => '__Directive'],
|
||||||
['name' => 'Boolean'],
|
|
||||||
['name' => '__Field'],
|
['name' => '__Field'],
|
||||||
['name' => '__InputValue'],
|
['name' => '__InputValue'],
|
||||||
['name' => '__EnumValue'],
|
['name' => '__EnumValue'],
|
||||||
['name' => '__Directive'],
|
['name' => '__TypeKind'],
|
||||||
['name' => '__DirectiveLocation'],
|
['name' => '__DirectiveLocation'],
|
||||||
['name' => 'ID'],
|
|
||||||
['name' => 'Float'],
|
|
||||||
['name' => 'Int']
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
@ -576,9 +576,8 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'types' => [$user, $blog]
|
'types' => [$user, $blog]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertFalse($called);
|
|
||||||
$schema->getType('Blog');
|
|
||||||
$this->assertTrue($called);
|
$this->assertTrue($called);
|
||||||
|
$schema->getType('Blog');
|
||||||
|
|
||||||
$this->assertEquals([$node], $blog->getInterfaces());
|
$this->assertEquals([$node], $blog->getInterfaces());
|
||||||
$this->assertEquals([$node], $user->getInterfaces());
|
$this->assertEquals([$node], $user->getInterfaces());
|
||||||
|
@ -74,6 +74,42 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'enumValues' => NULL,
|
'enumValues' => NULL,
|
||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'ID',
|
||||||
|
'fields' => NULL,
|
||||||
|
'inputFields' => NULL,
|
||||||
|
'interfaces' => NULL,
|
||||||
|
'enumValues' => NULL,
|
||||||
|
'possibleTypes' => NULL,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'Float',
|
||||||
|
'fields' => NULL,
|
||||||
|
'inputFields' => NULL,
|
||||||
|
'interfaces' => NULL,
|
||||||
|
'enumValues' => NULL,
|
||||||
|
'possibleTypes' => NULL,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'Int',
|
||||||
|
'fields' => NULL,
|
||||||
|
'inputFields' => NULL,
|
||||||
|
'interfaces' => NULL,
|
||||||
|
'enumValues' => NULL,
|
||||||
|
'possibleTypes' => NULL,
|
||||||
|
),
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'Boolean',
|
||||||
|
'fields' => NULL,
|
||||||
|
'inputFields' => NULL,
|
||||||
|
'interfaces' => NULL,
|
||||||
|
'enumValues' => NULL,
|
||||||
|
'possibleTypes' => NULL,
|
||||||
|
),
|
||||||
array (
|
array (
|
||||||
'kind' => 'OBJECT',
|
'kind' => 'OBJECT',
|
||||||
'name' => '__Schema',
|
'name' => '__Schema',
|
||||||
@ -404,70 +440,164 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'kind' => 'ENUM',
|
'kind' => 'OBJECT',
|
||||||
'name' => '__TypeKind',
|
'name' => '__Directive',
|
||||||
'fields' => NULL,
|
'fields' =>
|
||||||
'inputFields' => NULL,
|
|
||||||
'interfaces' => NULL,
|
|
||||||
'enumValues' =>
|
|
||||||
array (
|
array (
|
||||||
0 =>
|
0 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'SCALAR',
|
'name' => 'name',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'String',
|
||||||
|
),
|
||||||
|
),
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
1 =>
|
1 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'OBJECT',
|
'name' => 'description',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'String',
|
||||||
|
),
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
2 =>
|
2 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'INTERFACE',
|
'name' => 'locations',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'LIST',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'ENUM',
|
||||||
|
'name' => '__DirectiveLocation',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
3 =>
|
3 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'UNION',
|
'name' => 'args',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'LIST',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'OBJECT',
|
||||||
|
'name' => '__InputValue',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
4 =>
|
4 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'ENUM',
|
'name' => 'onOperation',
|
||||||
'isDeprecated' => false,
|
'args' =>
|
||||||
'deprecationReason' => NULL,
|
|
||||||
),
|
|
||||||
5 =>
|
|
||||||
array (
|
array (
|
||||||
'name' => 'INPUT_OBJECT',
|
|
||||||
'isDeprecated' => false,
|
|
||||||
'deprecationReason' => NULL,
|
|
||||||
),
|
),
|
||||||
6 =>
|
'type' =>
|
||||||
array (
|
array (
|
||||||
'name' => 'LIST',
|
'kind' => 'NON_NULL',
|
||||||
'isDeprecated' => false,
|
'name' => NULL,
|
||||||
'deprecationReason' => NULL,
|
'ofType' =>
|
||||||
),
|
|
||||||
7 =>
|
|
||||||
array (
|
|
||||||
'name' => 'NON_NULL',
|
|
||||||
'isDeprecated' => false,
|
|
||||||
'deprecationReason' => NULL,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'possibleTypes' => NULL,
|
|
||||||
),
|
|
||||||
array (
|
array (
|
||||||
'kind' => 'SCALAR',
|
'kind' => 'SCALAR',
|
||||||
'name' => 'Boolean',
|
'name' => 'Boolean',
|
||||||
'fields' => NULL,
|
),
|
||||||
|
),
|
||||||
|
'isDeprecated' => true,
|
||||||
|
'deprecationReason' => 'Use `locations`.',
|
||||||
|
),
|
||||||
|
5 =>
|
||||||
|
array (
|
||||||
|
'name' => 'onFragment',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'Boolean',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'isDeprecated' => true,
|
||||||
|
'deprecationReason' => 'Use `locations`.',
|
||||||
|
),
|
||||||
|
6 =>
|
||||||
|
array (
|
||||||
|
'name' => 'onField',
|
||||||
|
'args' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
|
'type' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'NON_NULL',
|
||||||
|
'name' => NULL,
|
||||||
|
'ofType' =>
|
||||||
|
array (
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'Boolean',
|
||||||
|
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'isDeprecated' => true,
|
||||||
|
'deprecationReason' => 'Use `locations`.',
|
||||||
|
),
|
||||||
|
),
|
||||||
'inputFields' => NULL,
|
'inputFields' => NULL,
|
||||||
'interfaces' => NULL,
|
'interfaces' =>
|
||||||
|
array (
|
||||||
|
),
|
||||||
'enumValues' => NULL,
|
'enumValues' => NULL,
|
||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
@ -757,165 +887,62 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
'kind' => 'OBJECT',
|
'kind' => 'ENUM',
|
||||||
'name' => '__Directive',
|
'name' => '__TypeKind',
|
||||||
'fields' =>
|
'fields' => NULL,
|
||||||
|
'inputFields' => NULL,
|
||||||
|
'interfaces' => NULL,
|
||||||
|
'enumValues' =>
|
||||||
array (
|
array (
|
||||||
0 =>
|
0 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'name',
|
'name' => 'SCALAR',
|
||||||
'args' =>
|
|
||||||
array (
|
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'String',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
1 =>
|
1 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'description',
|
'name' => 'OBJECT',
|
||||||
'args' =>
|
|
||||||
array (
|
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'String',
|
|
||||||
),
|
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
2 =>
|
2 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'locations',
|
'name' => 'INTERFACE',
|
||||||
'args' =>
|
|
||||||
array (
|
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'LIST',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'ENUM',
|
|
||||||
'name' => '__DirectiveLocation',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
3 =>
|
3 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'args',
|
'name' => 'UNION',
|
||||||
'args' =>
|
|
||||||
array (
|
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'LIST',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'OBJECT',
|
|
||||||
'name' => '__InputValue',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'isDeprecated' => false,
|
'isDeprecated' => false,
|
||||||
'deprecationReason' => NULL,
|
'deprecationReason' => NULL,
|
||||||
),
|
),
|
||||||
4 =>
|
4 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'onOperation',
|
'name' => 'ENUM',
|
||||||
'args' =>
|
'isDeprecated' => false,
|
||||||
array (
|
'deprecationReason' => NULL,
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'Boolean',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'isDeprecated' => true,
|
|
||||||
'deprecationReason' => 'Use `locations`.',
|
|
||||||
),
|
),
|
||||||
5 =>
|
5 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'onFragment',
|
'name' => 'INPUT_OBJECT',
|
||||||
'args' =>
|
'isDeprecated' => false,
|
||||||
array (
|
'deprecationReason' => NULL,
|
||||||
),
|
|
||||||
'type' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'Boolean',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'isDeprecated' => true,
|
|
||||||
'deprecationReason' => 'Use `locations`.',
|
|
||||||
),
|
),
|
||||||
6 =>
|
6 =>
|
||||||
array (
|
array (
|
||||||
'name' => 'onField',
|
'name' => 'LIST',
|
||||||
'args' =>
|
'isDeprecated' => false,
|
||||||
|
'deprecationReason' => NULL,
|
||||||
|
),
|
||||||
|
7 =>
|
||||||
array (
|
array (
|
||||||
),
|
'name' => 'NON_NULL',
|
||||||
'type' =>
|
'isDeprecated' => false,
|
||||||
array (
|
'deprecationReason' => NULL,
|
||||||
'kind' => 'NON_NULL',
|
|
||||||
'name' => NULL,
|
|
||||||
'ofType' =>
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'Boolean',
|
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'isDeprecated' => true,
|
|
||||||
'deprecationReason' => 'Use `locations`.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'inputFields' => NULL,
|
|
||||||
'interfaces' =>
|
|
||||||
array (
|
|
||||||
),
|
|
||||||
'enumValues' => NULL,
|
|
||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
array (
|
array (
|
||||||
@ -971,33 +998,6 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
),
|
),
|
||||||
'possibleTypes' => NULL,
|
'possibleTypes' => NULL,
|
||||||
),
|
),
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'ID',
|
|
||||||
'fields' => NULL,
|
|
||||||
'inputFields' => NULL,
|
|
||||||
'interfaces' => NULL,
|
|
||||||
'enumValues' => NULL,
|
|
||||||
'possibleTypes' => NULL,
|
|
||||||
),
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'Float',
|
|
||||||
'fields' => NULL,
|
|
||||||
'inputFields' => NULL,
|
|
||||||
'interfaces' => NULL,
|
|
||||||
'enumValues' => NULL,
|
|
||||||
'possibleTypes' => NULL,
|
|
||||||
),
|
|
||||||
array (
|
|
||||||
'kind' => 'SCALAR',
|
|
||||||
'name' => 'Int',
|
|
||||||
'fields' => NULL,
|
|
||||||
'inputFields' => NULL,
|
|
||||||
'interfaces' => NULL,
|
|
||||||
'enumValues' => NULL,
|
|
||||||
'possibleTypes' => NULL,
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
'directives' =>
|
'directives' =>
|
||||||
array (
|
array (
|
||||||
|
@ -230,7 +230,7 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it TODO: accepts a Schema whose query and mutation types are object types
|
* @it accepts a Schema whose query and mutation types are object types
|
||||||
*/
|
*/
|
||||||
public function testAcceptsASchemaWhoseQueryAndMutationTypesAreObjectTypes()
|
public function testAcceptsASchemaWhoseQueryAndMutationTypesAreObjectTypes()
|
||||||
{
|
{
|
||||||
@ -357,13 +357,11 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$schema = new Schema(['query' => $QueryType]);
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'Schema must contain unique named types but contains multiple types named "String".'
|
'Schema must contain unique named types but contains multiple types named "String".'
|
||||||
);
|
);
|
||||||
$schema->assertValid();
|
new Schema(['query' => $QueryType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -389,14 +387,12 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$schema = new Schema([ 'query' => $QueryType ]);
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'Schema must contain unique named types but contains multiple types named "SameName".'
|
'Schema must contain unique named types but contains multiple types named "SameName".'
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema->assertValid();
|
new Schema([ 'query' => $QueryType ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,17 +425,15 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$schema = new Schema([
|
|
||||||
'query' => $QueryType,
|
|
||||||
'types' => [ $FirstBadObject, $SecondBadObject ]
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'Schema must contain unique named types but contains multiple types named "BadObject".'
|
'Schema must contain unique named types but contains multiple types named "BadObject".'
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema->assertValid();
|
new Schema([
|
||||||
|
'query' => $QueryType,
|
||||||
|
'types' => [ $FirstBadObject, $SecondBadObject ]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -498,17 +492,16 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnObjectTypeFieldWithUndefinedConfig()
|
public function testRejectsAnObjectTypeFieldWithUndefinedConfig()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithFieldType(new ObjectType([
|
$this->setExpectedException(
|
||||||
|
InvariantViolation::class,
|
||||||
|
'SomeObject.f field config must be an array, but got'
|
||||||
|
);
|
||||||
|
$this->schemaWithFieldType(new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'f' => null
|
'f' => null
|
||||||
]
|
]
|
||||||
]));
|
]));
|
||||||
$this->setExpectedException(
|
|
||||||
InvariantViolation::class,
|
|
||||||
'SomeObject.f field config must be an array, but got'
|
|
||||||
);
|
|
||||||
$schema->assertValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -609,16 +602,14 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnObjectTypeWithAFieldFunctionThatReturnsNothing()
|
public function testRejectsAnObjectTypeWithAFieldFunctionThatReturnsNothing()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithFieldType(new ObjectType([
|
|
||||||
'name' => 'SomeObject',
|
|
||||||
'fields' => function() {}
|
|
||||||
]));
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'SomeObject fields must be an array or a callable which returns such an array.'
|
'SomeObject fields must be an array or a callable which returns such an array.'
|
||||||
);
|
);
|
||||||
$schema->assertValid();
|
$this->schemaWithFieldType(new ObjectType([
|
||||||
|
'name' => 'SomeObject',
|
||||||
|
'fields' => function() {}
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -782,17 +773,15 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnObjectTypeWithIncorrectlyTypedInterfaces()
|
public function testRejectsAnObjectTypeWithIncorrectlyTypedInterfaces()
|
||||||
{
|
{
|
||||||
|
$this->setExpectedException(
|
||||||
|
InvariantViolation::class,
|
||||||
|
'SomeObject interfaces must be an Array or a callable which returns an Array.'
|
||||||
|
);
|
||||||
$schema = $this->schemaWithFieldType(new ObjectType([
|
$schema = $this->schemaWithFieldType(new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'interfaces' => new \stdClass(),
|
'interfaces' => new \stdClass(),
|
||||||
'fields' => ['f' => ['type' => Type::string()]]
|
'fields' => ['f' => ['type' => Type::string()]]
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->setExpectedException(
|
|
||||||
InvariantViolation::class,
|
|
||||||
'SomeObject interfaces must be an Array or a callable which returns an Array.'
|
|
||||||
);
|
|
||||||
|
|
||||||
$schema->assertValid();
|
$schema->assertValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,20 +826,17 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnObjectTypeWithInterfacesAsAFunctionReturningAnIncorrectType()
|
public function testRejectsAnObjectTypeWithInterfacesAsAFunctionReturningAnIncorrectType()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithFieldType(new ObjectType([
|
$this->setExpectedException(
|
||||||
|
InvariantViolation::class,
|
||||||
|
'SomeObject interfaces must be an Array or a callable which returns an Array.'
|
||||||
|
);
|
||||||
|
$this->schemaWithFieldType(new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'interfaces' => function () {
|
'interfaces' => function () {
|
||||||
return new \stdClass();
|
return new \stdClass();
|
||||||
},
|
},
|
||||||
'fields' => ['f' => ['type' => Type::string()]]
|
'fields' => ['f' => ['type' => Type::string()]]
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->setExpectedException(
|
|
||||||
InvariantViolation::class,
|
|
||||||
'SomeObject interfaces must be an Array or a callable which returns an Array.'
|
|
||||||
);
|
|
||||||
|
|
||||||
$schema->assertValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DESCRIBE: Type System: Union types must be array
|
// DESCRIBE: Type System: Union types must be array
|
||||||
@ -892,17 +878,14 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAUnionTypeWithoutTypes()
|
public function testRejectsAUnionTypeWithoutTypes()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithFieldType(new UnionType([
|
|
||||||
'name' => 'SomeUnion',
|
|
||||||
'resolveType' => function() {return null;}
|
|
||||||
]));
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'SomeUnion types must be an Array or a callable which returns an Array.'
|
'SomeUnion types must be an Array or a callable which returns an Array.'
|
||||||
);
|
);
|
||||||
|
$this->schemaWithFieldType(new UnionType([
|
||||||
$schema->assertValid();
|
'name' => 'SomeUnion',
|
||||||
|
'resolveType' => function() {return null;}
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -929,18 +912,16 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAUnionTypeWithIncorrectlyTypedTypes()
|
public function testRejectsAUnionTypeWithIncorrectlyTypedTypes()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithFieldType(new UnionType([
|
$this->setExpectedException(
|
||||||
|
InvariantViolation::class,
|
||||||
|
'SomeUnion types must be an Array or a callable which returns an Array.'
|
||||||
|
);
|
||||||
|
$this->schemaWithFieldType(new UnionType([
|
||||||
'name' => 'SomeUnion',
|
'name' => 'SomeUnion',
|
||||||
'resolveType' => function () {
|
'resolveType' => function () {
|
||||||
},
|
},
|
||||||
'types' => $this->SomeObjectType
|
'types' => $this->SomeObjectType
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->setExpectedException(
|
|
||||||
InvariantViolation::class,
|
|
||||||
'SomeUnion types must be an Array or a callable which returns an Array.'
|
|
||||||
);
|
|
||||||
$schema->assertValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1038,16 +1019,14 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnInputObjectTypeWithEmptyFields()
|
public function testRejectsAnInputObjectTypeWithEmptyFields()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithInputObject(new InputObjectType([
|
|
||||||
'name' => 'SomeInputObject',
|
|
||||||
'fields' => new \stdClass()
|
|
||||||
]));
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
||||||
);
|
);
|
||||||
$schema->assertValid();
|
$this->schemaWithInputObject(new InputObjectType([
|
||||||
|
'name' => 'SomeInputObject',
|
||||||
|
'fields' => new \stdClass()
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1055,18 +1034,15 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnInputObjectTypeWithAFieldFunctionThatReturnsNothing()
|
public function testRejectsAnInputObjectTypeWithAFieldFunctionThatReturnsNothing()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithInputObject(new ObjectType([
|
|
||||||
'name' => 'SomeInputObject',
|
|
||||||
'fields' => function () {
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
|
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
InvariantViolation::class,
|
InvariantViolation::class,
|
||||||
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
||||||
);
|
);
|
||||||
|
$this->schemaWithInputObject(new ObjectType([
|
||||||
$schema->assertValid();
|
'name' => 'SomeInputObject',
|
||||||
|
'fields' => function () {
|
||||||
|
}
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1074,19 +1050,16 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRejectsAnInputObjectTypeWithAFieldFunctionThatReturnsEmpty()
|
public function testRejectsAnInputObjectTypeWithAFieldFunctionThatReturnsEmpty()
|
||||||
{
|
{
|
||||||
$schema = $this->schemaWithInputObject(new InputObjectType([
|
$this->setExpectedException(
|
||||||
|
InvariantViolation::class,
|
||||||
|
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
||||||
|
);
|
||||||
|
$this->schemaWithInputObject(new InputObjectType([
|
||||||
'name' => 'SomeInputObject',
|
'name' => 'SomeInputObject',
|
||||||
'fields' => function () {
|
'fields' => function () {
|
||||||
return new \stdClass();
|
return new \stdClass();
|
||||||
}
|
}
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->setExpectedException(
|
|
||||||
InvariantViolation::class,
|
|
||||||
'SomeInputObject fields must be an array or a callable which returns such an array.'
|
|
||||||
);
|
|
||||||
|
|
||||||
$schema->assertValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DESCRIBE: Type System: Input Object fields must not have resolvers
|
// DESCRIBE: Type System: Input Object fields must not have resolvers
|
||||||
@ -1222,12 +1195,11 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
'fields' => ['f' => ['type' => Type::string()]]
|
'fields' => ['f' => ['type' => Type::string()]]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$schema = $this->schemaWithFieldType(new ObjectType([
|
$this->schemaWithFieldType(new ObjectType([
|
||||||
'name' => 'SomeObject',
|
'name' => 'SomeObject',
|
||||||
'interfaces' => [$AnotherInterfaceType],
|
'interfaces' => [$AnotherInterfaceType],
|
||||||
'fields' => ['f' => ['type' => Type::string()]]
|
'fields' => ['f' => ['type' => Type::string()]]
|
||||||
]));
|
]));
|
||||||
$schema->assertValid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1322,7 +1294,6 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DESCRIBE: Type System: Union types must be resolvable
|
// DESCRIBE: Type System: Union types must be resolvable
|
||||||
// TODO: accepts a Union type defining resolveType
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it accepts a Union type defining resolveType
|
* @it accepts a Union type defining resolveType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user