mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-16 12:23:15 +03:00
Forbid duplicate type definitions
This commit is contained in:
parent
c3db8de9e7
commit
76e182e616
@ -112,8 +112,12 @@ class BuildSchema
|
||||
case NodeKind::ENUM_TYPE_DEFINITION:
|
||||
case NodeKind::UNION_TYPE_DEFINITION:
|
||||
case NodeKind::INPUT_OBJECT_TYPE_DEFINITION:
|
||||
$typeName = $d->name->value;
|
||||
if (!empty($this->nodeMap[$typeName])) {
|
||||
throw new Error("Type \"$typeName\" was defined more than once.");
|
||||
}
|
||||
$typeDefs[] = $d;
|
||||
$this->nodeMap[$d->name->value] = $d;
|
||||
$this->nodeMap[$typeName] = $d;
|
||||
break;
|
||||
case NodeKind::DIRECTIVE_DEFINITION:
|
||||
$directiveDefs[] = $d;
|
||||
@ -453,6 +457,12 @@ class BuildSchema
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a collection of directives, returns the string value for the
|
||||
* deprecation reason.
|
||||
*
|
||||
* @param $directives
|
||||
*/
|
||||
private function getDeprecationReason($directives)
|
||||
{
|
||||
$deprecatedAST = $directives ? Utils::find(
|
||||
|
@ -896,4 +896,28 @@ fragment Foo on Type { field }
|
||||
$doc = Parser::parse($body);
|
||||
BuildSchema::buildAST($doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @it Forbids duplicate type definitions
|
||||
*/
|
||||
public function testForbidsDuplicateTypeDefinitions()
|
||||
{
|
||||
$body = '
|
||||
schema {
|
||||
query: Repeated
|
||||
}
|
||||
|
||||
type Repeated {
|
||||
id: Int
|
||||
}
|
||||
|
||||
type Repeated {
|
||||
id: String
|
||||
}
|
||||
';
|
||||
$doc = Parser::parse($body);
|
||||
|
||||
$this->setExpectedException('GraphQL\Error\Error', 'Type "Repeated" was defined more than once.');
|
||||
BuildSchema::buildAST($doc);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user