mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Replaced directive locations array with constants
This commit is contained in:
parent
1927102183
commit
add2621a33
@ -14,31 +14,54 @@ class Directive
|
|||||||
*/
|
*/
|
||||||
public static $internalDirectives;
|
public static $internalDirectives;
|
||||||
|
|
||||||
|
const LOCATION_QUERY = 'QUERY';
|
||||||
|
const LOCATION_MUTATION = 'MUTATION';
|
||||||
|
const LOCATION_SUBSCRIPTION = 'SUBSCRIPTION';
|
||||||
|
const LOCATION_FIELD = 'FIELD';
|
||||||
|
const LOCATION_FRAGMENT_DEFINITION = 'FRAGMENT_DEFINITION';
|
||||||
|
const LOCATION_FRAGMENT_SPREAD = 'FRAGMENT_SPREAD';
|
||||||
|
const LOCATION_INLINE_FRAGMENT = 'INLINE_FRAGMENT';
|
||||||
|
|
||||||
|
// Schema Definitions
|
||||||
|
const LOCATION_SCHEMA = 'SCHEMA';
|
||||||
|
const LOCATION_SCALAR = 'SCALAR';
|
||||||
|
const LOCATION_OBJECT = 'OBJECT';
|
||||||
|
const LOCATION_FIELD_DEFINITION = 'FIELD_DEFINITION';
|
||||||
|
const LOCATION_ARGUMENT_DEFINITION = 'ARGUMENT_DEFINITION';
|
||||||
|
const LOCATION_INTERFACE = 'INTERFACE';
|
||||||
|
const LOCATION_UNION = 'UNION';
|
||||||
|
const LOCATION_ENUM = 'ENUM';
|
||||||
|
const LOCATION_ENUM_VALUE = 'ENUM_VALUE';
|
||||||
|
const LOCATION_INPUT_OBJECT = 'INPUT_OBJECT';
|
||||||
|
const LOCATION_INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
* @deprecated Just use constants directly
|
||||||
*/
|
*/
|
||||||
public static $directiveLocations = [
|
public static $directiveLocations = [
|
||||||
// Operations:
|
// Operations:
|
||||||
'QUERY' => 'QUERY',
|
self::LOCATION_QUERY => self::LOCATION_QUERY,
|
||||||
'MUTATION' => 'MUTATION',
|
self::LOCATION_MUTATION => self::LOCATION_MUTATION,
|
||||||
'SUBSCRIPTION' => 'SUBSCRIPTION',
|
self::LOCATION_SUBSCRIPTION => self::LOCATION_SUBSCRIPTION,
|
||||||
'FIELD' => 'FIELD',
|
self::LOCATION_FIELD => self::LOCATION_FIELD,
|
||||||
'FRAGMENT_DEFINITION' => 'FRAGMENT_DEFINITION',
|
self::LOCATION_FRAGMENT_DEFINITION => self::LOCATION_FRAGMENT_DEFINITION,
|
||||||
'FRAGMENT_SPREAD' => 'FRAGMENT_SPREAD',
|
self::LOCATION_FRAGMENT_SPREAD => self::LOCATION_FRAGMENT_SPREAD,
|
||||||
'INLINE_FRAGMENT' => 'INLINE_FRAGMENT',
|
self::LOCATION_INLINE_FRAGMENT => self::LOCATION_INLINE_FRAGMENT,
|
||||||
|
|
||||||
// Schema Definitions
|
// Schema Definitions
|
||||||
'SCHEMA' => 'SCHEMA',
|
self::LOCATION_SCHEMA => self::LOCATION_SCHEMA,
|
||||||
'SCALAR' => 'SCALAR',
|
self::LOCATION_SCALAR => self::LOCATION_SCALAR,
|
||||||
'OBJECT' => 'OBJECT',
|
self::LOCATION_OBJECT => self::LOCATION_OBJECT,
|
||||||
'FIELD_DEFINITION' => 'FIELD_DEFINITION',
|
self::LOCATION_FIELD_DEFINITION => self::LOCATION_FIELD_DEFINITION,
|
||||||
'ARGUMENT_DEFINITION' => 'ARGUMENT_DEFINITION',
|
self::LOCATION_ARGUMENT_DEFINITION => self::LOCATION_ARGUMENT_DEFINITION,
|
||||||
'INTERFACE' => 'INTERFACE',
|
self::LOCATION_INTERFACE => self::LOCATION_INTERFACE,
|
||||||
'UNION' => 'UNION',
|
self::LOCATION_UNION => self::LOCATION_UNION,
|
||||||
'ENUM' => 'ENUM',
|
self::LOCATION_ENUM => self::LOCATION_ENUM,
|
||||||
'ENUM_VALUE' => 'ENUM_VALUE',
|
self::LOCATION_ENUM_VALUE => self::LOCATION_ENUM_VALUE,
|
||||||
'INPUT_OBJECT' => 'INPUT_OBJECT',
|
self::LOCATION_INPUT_OBJECT => self::LOCATION_INPUT_OBJECT,
|
||||||
'INPUT_FIELD_DEFINITION' => 'INPUT_FIELD_DEFINITION'
|
self::LOCATION_INPUT_FIELD_DEFINITION => self::LOCATION_INPUT_FIELD_DEFINITION
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,9 +102,9 @@ class Directive
|
|||||||
'name' => 'include',
|
'name' => 'include',
|
||||||
'description' => 'Directs the executor to include this field or fragment only when the `if` argument is true.',
|
'description' => 'Directs the executor to include this field or fragment only when the `if` argument is true.',
|
||||||
'locations' => [
|
'locations' => [
|
||||||
self::$directiveLocations['FIELD'],
|
self::LOCATION_FIELD,
|
||||||
self::$directiveLocations['FRAGMENT_SPREAD'],
|
self::LOCATION_FRAGMENT_SPREAD,
|
||||||
self::$directiveLocations['INLINE_FRAGMENT'],
|
self::LOCATION_INLINE_FRAGMENT,
|
||||||
],
|
],
|
||||||
'args' => [
|
'args' => [
|
||||||
new FieldArgument([
|
new FieldArgument([
|
||||||
@ -95,9 +118,9 @@ class Directive
|
|||||||
'name' => 'skip',
|
'name' => 'skip',
|
||||||
'description' => 'Directs the executor to skip this field or fragment when the `if` argument is true.',
|
'description' => 'Directs the executor to skip this field or fragment when the `if` argument is true.',
|
||||||
'locations' => [
|
'locations' => [
|
||||||
self::$directiveLocations['FIELD'],
|
self::LOCATION_FIELD,
|
||||||
self::$directiveLocations['FRAGMENT_SPREAD'],
|
self::LOCATION_FRAGMENT_SPREAD,
|
||||||
self::$directiveLocations['INLINE_FRAGMENT']
|
self::LOCATION_INLINE_FRAGMENT
|
||||||
],
|
],
|
||||||
'args' => [
|
'args' => [
|
||||||
new FieldArgument([
|
new FieldArgument([
|
||||||
@ -111,8 +134,8 @@ class Directive
|
|||||||
'name' => 'deprecated',
|
'name' => 'deprecated',
|
||||||
'description' => 'Marks an element of a GraphQL schema as no longer supported.',
|
'description' => 'Marks an element of a GraphQL schema as no longer supported.',
|
||||||
'locations' => [
|
'locations' => [
|
||||||
self::$directiveLocations['FIELD_DEFINITION'],
|
self::LOCATION_FIELD_DEFINITION,
|
||||||
self::$directiveLocations['ENUM_VALUE']
|
self::LOCATION_ENUM_VALUE
|
||||||
],
|
],
|
||||||
'args' => [
|
'args' => [
|
||||||
new FieldArgument([
|
new FieldArgument([
|
||||||
|
@ -310,25 +310,25 @@ EOD;
|
|||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => function($d) {
|
'resolve' => function($d) {
|
||||||
return in_array(Directive::$directiveLocations['QUERY'], $d->locations) ||
|
return in_array(Directive::LOCATION_QUERY, $d->locations) ||
|
||||||
in_array(Directive::$directiveLocations['MUTATION'], $d->locations) ||
|
in_array(Directive::LOCATION_MUTATION, $d->locations) ||
|
||||||
in_array(Directive::$directiveLocations['SUBSCRIPTION'], $d->locations);
|
in_array(Directive::LOCATION_SUBSCRIPTION, $d->locations);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'onFragment' => [
|
'onFragment' => [
|
||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => function($d) {
|
'resolve' => function($d) {
|
||||||
return in_array(Directive::$directiveLocations['FRAGMENT_SPREAD'], $d->locations) ||
|
return in_array(Directive::LOCATION_FRAGMENT_SPREAD, $d->locations) ||
|
||||||
in_array(Directive::$directiveLocations['INLINE_FRAGMENT'], $d->locations) ||
|
in_array(Directive::LOCATION_INLINE_FRAGMENT, $d->locations) ||
|
||||||
in_array(Directive::$directiveLocations['FRAGMENT_DEFINITION'], $d->locations);
|
in_array(Directive::LOCATION_FRAGMENT_DEFINITION, $d->locations);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'onField' => [
|
'onField' => [
|
||||||
'deprecationReason' => 'Use `locations`.',
|
'deprecationReason' => 'Use `locations`.',
|
||||||
'type' => Type::nonNull(Type::boolean()),
|
'type' => Type::nonNull(Type::boolean()),
|
||||||
'resolve' => function($d) {
|
'resolve' => function($d) {
|
||||||
return in_array(Directive::$directiveLocations['FIELD'], $d->locations);
|
return in_array(Directive::LOCATION_FIELD, $d->locations);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -347,75 +347,75 @@ EOD;
|
|||||||
'__DirectiveLocation describes one such possible adjacencies.',
|
'__DirectiveLocation describes one such possible adjacencies.',
|
||||||
'values' => [
|
'values' => [
|
||||||
'QUERY' => [
|
'QUERY' => [
|
||||||
'value' => Directive::$directiveLocations['QUERY'],
|
'value' => Directive::LOCATION_QUERY,
|
||||||
'description' => 'Location adjacent to a query operation.'
|
'description' => 'Location adjacent to a query operation.'
|
||||||
],
|
],
|
||||||
'MUTATION' => [
|
'MUTATION' => [
|
||||||
'value' => Directive::$directiveLocations['MUTATION'],
|
'value' => Directive::LOCATION_MUTATION,
|
||||||
'description' => 'Location adjacent to a mutation operation.'
|
'description' => 'Location adjacent to a mutation operation.'
|
||||||
],
|
],
|
||||||
'SUBSCRIPTION' => [
|
'SUBSCRIPTION' => [
|
||||||
'value' => Directive::$directiveLocations['SUBSCRIPTION'],
|
'value' => Directive::LOCATION_SUBSCRIPTION,
|
||||||
'description' => 'Location adjacent to a subscription operation.'
|
'description' => 'Location adjacent to a subscription operation.'
|
||||||
],
|
],
|
||||||
'FIELD' => [
|
'FIELD' => [
|
||||||
'value' => Directive::$directiveLocations['FIELD'],
|
'value' => Directive::LOCATION_FIELD,
|
||||||
'description' => 'Location adjacent to a field.'
|
'description' => 'Location adjacent to a field.'
|
||||||
],
|
],
|
||||||
'FRAGMENT_DEFINITION' => [
|
'FRAGMENT_DEFINITION' => [
|
||||||
'value' => Directive::$directiveLocations['FRAGMENT_DEFINITION'],
|
'value' => Directive::LOCATION_FRAGMENT_DEFINITION,
|
||||||
'description' => 'Location adjacent to a fragment definition.'
|
'description' => 'Location adjacent to a fragment definition.'
|
||||||
],
|
],
|
||||||
'FRAGMENT_SPREAD' => [
|
'FRAGMENT_SPREAD' => [
|
||||||
'value' => Directive::$directiveLocations['FRAGMENT_SPREAD'],
|
'value' => Directive::LOCATION_FRAGMENT_SPREAD,
|
||||||
'description' => 'Location adjacent to a fragment spread.'
|
'description' => 'Location adjacent to a fragment spread.'
|
||||||
],
|
],
|
||||||
'INLINE_FRAGMENT' => [
|
'INLINE_FRAGMENT' => [
|
||||||
'value' => Directive::$directiveLocations['INLINE_FRAGMENT'],
|
'value' => Directive::LOCATION_INLINE_FRAGMENT,
|
||||||
'description' => 'Location adjacent to an inline fragment.'
|
'description' => 'Location adjacent to an inline fragment.'
|
||||||
],
|
],
|
||||||
'SCHEMA' => [
|
'SCHEMA' => [
|
||||||
'value' => Directive::$directiveLocations['SCHEMA'],
|
'value' => Directive::LOCATION_SCHEMA,
|
||||||
'description' => 'Location adjacent to a schema definition.'
|
'description' => 'Location adjacent to a schema definition.'
|
||||||
],
|
],
|
||||||
'SCALAR' => [
|
'SCALAR' => [
|
||||||
'value' => Directive::$directiveLocations['SCALAR'],
|
'value' => Directive::LOCATION_SCALAR,
|
||||||
'description' => 'Location adjacent to a scalar definition.'
|
'description' => 'Location adjacent to a scalar definition.'
|
||||||
],
|
],
|
||||||
'OBJECT' => [
|
'OBJECT' => [
|
||||||
'value' => Directive::$directiveLocations['OBJECT'],
|
'value' => Directive::LOCATION_OBJECT,
|
||||||
'description' => 'Location adjacent to an object type definition.'
|
'description' => 'Location adjacent to an object type definition.'
|
||||||
],
|
],
|
||||||
'FIELD_DEFINITION' => [
|
'FIELD_DEFINITION' => [
|
||||||
'value' => Directive::$directiveLocations['FIELD_DEFINITION'],
|
'value' => Directive::LOCATION_FIELD_DEFINITION,
|
||||||
'description' => 'Location adjacent to a field definition.'
|
'description' => 'Location adjacent to a field definition.'
|
||||||
],
|
],
|
||||||
'ARGUMENT_DEFINITION' => [
|
'ARGUMENT_DEFINITION' => [
|
||||||
'value' => Directive::$directiveLocations['ARGUMENT_DEFINITION'],
|
'value' => Directive::LOCATION_ARGUMENT_DEFINITION,
|
||||||
'description' => 'Location adjacent to an argument definition.'
|
'description' => 'Location adjacent to an argument definition.'
|
||||||
],
|
],
|
||||||
'INTERFACE' => [
|
'INTERFACE' => [
|
||||||
'value' => Directive::$directiveLocations['INTERFACE'],
|
'value' => Directive::LOCATION_INTERFACE,
|
||||||
'description' => 'Location adjacent to an interface definition.'
|
'description' => 'Location adjacent to an interface definition.'
|
||||||
],
|
],
|
||||||
'UNION' => [
|
'UNION' => [
|
||||||
'value' => Directive::$directiveLocations['UNION'],
|
'value' => Directive::LOCATION_UNION,
|
||||||
'description' => 'Location adjacent to a union definition.'
|
'description' => 'Location adjacent to a union definition.'
|
||||||
],
|
],
|
||||||
'ENUM' => [
|
'ENUM' => [
|
||||||
'value' => Directive::$directiveLocations['ENUM'],
|
'value' => Directive::LOCATION_ENUM,
|
||||||
'description' => 'Location adjacent to an enum definition.'
|
'description' => 'Location adjacent to an enum definition.'
|
||||||
],
|
],
|
||||||
'ENUM_VALUE' => [
|
'ENUM_VALUE' => [
|
||||||
'value' => Directive::$directiveLocations['ENUM_VALUE'],
|
'value' => Directive::LOCATION_ENUM_VALUE,
|
||||||
'description' => 'Location adjacent to an enum value definition.'
|
'description' => 'Location adjacent to an enum value definition.'
|
||||||
],
|
],
|
||||||
'INPUT_OBJECT' => [
|
'INPUT_OBJECT' => [
|
||||||
'value' => Directive::$directiveLocations['INPUT_OBJECT'],
|
'value' => Directive::LOCATION_INPUT_OBJECT,
|
||||||
'description' => 'Location adjacent to an input object type definition.'
|
'description' => 'Location adjacent to an input object type definition.'
|
||||||
],
|
],
|
||||||
'INPUT_FIELD_DEFINITION' => [
|
'INPUT_FIELD_DEFINITION' => [
|
||||||
'value' => Directive::$directiveLocations['INPUT_FIELD_DEFINITION'],
|
'value' => Directive::LOCATION_INPUT_FIELD_DEFINITION,
|
||||||
'description' => 'Location adjacent to an input object field definition.'
|
'description' => 'Location adjacent to an input object field definition.'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -68,15 +68,15 @@ class KnownDirectives
|
|||||||
switch ($appliedTo->kind) {
|
switch ($appliedTo->kind) {
|
||||||
case Node::OPERATION_DEFINITION:
|
case Node::OPERATION_DEFINITION:
|
||||||
switch ($appliedTo->operation) {
|
switch ($appliedTo->operation) {
|
||||||
case 'query': return DirectiveDef::$directiveLocations['QUERY'];
|
case 'query': return DirectiveDef::LOCATION_QUERY;
|
||||||
case 'mutation': return DirectiveDef::$directiveLocations['MUTATION'];
|
case 'mutation': return DirectiveDef::LOCATION_MUTATION;
|
||||||
case 'subscription': return DirectiveDef::$directiveLocations['SUBSCRIPTION'];
|
case 'subscription': return DirectiveDef::LOCATION_SUBSCRIPTION;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Node::FIELD: return DirectiveDef::$directiveLocations['FIELD'];
|
case Node::FIELD: return DirectiveDef::LOCATION_FIELD;
|
||||||
case Node::FRAGMENT_SPREAD: return DirectiveDef::$directiveLocations['FRAGMENT_SPREAD'];
|
case Node::FRAGMENT_SPREAD: return DirectiveDef::LOCATION_FRAGMENT_SPREAD;
|
||||||
case Node::INLINE_FRAGMENT: return DirectiveDef::$directiveLocations['INLINE_FRAGMENT'];
|
case Node::INLINE_FRAGMENT: return DirectiveDef::LOCATION_INLINE_FRAGMENT;
|
||||||
case Node::FRAGMENT_DEFINITION: return DirectiveDef::$directiveLocations['FRAGMENT_DEFINITION'];
|
case Node::FRAGMENT_DEFINITION: return DirectiveDef::LOCATION_FRAGMENT_DEFINITION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user