Skip to content

Commit f7c99d2

Browse files
authored
Expose structured enumeration of directive locations (#918)
1 parent ca5fab2 commit f7c99d2

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
2424
- Improve extendability of validator rules
2525
- Add tests for errors that occur when undeclared fields are passed in input
2626
- Warn about orphaned object types
27+
- Expose structured enumeration of directive locations
2728

2829
### Optimized
2930

src/Language/DirectiveLocation.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
namespace GraphQL\Language;
66

77
/**
8-
* List of available directive locations
8+
* Enumeration of available directive locations.
99
*/
1010
class DirectiveLocation
1111
{
12-
// Request Definitions
1312
const QUERY = 'QUERY';
1413
const MUTATION = 'MUTATION';
1514
const SUBSCRIPTION = 'SUBSCRIPTION';
@@ -19,7 +18,17 @@ class DirectiveLocation
1918
const INLINE_FRAGMENT = 'INLINE_FRAGMENT';
2019
const VARIABLE_DEFINITION = 'VARIABLE_DEFINITION';
2120

22-
// Type System Definitions
21+
const EXECUTABLE_LOCATIONS = [
22+
self::QUERY => self::QUERY,
23+
self::MUTATION => self::MUTATION,
24+
self::SUBSCRIPTION => self::SUBSCRIPTION,
25+
self::FIELD => self::FIELD,
26+
self::FRAGMENT_DEFINITION => self::FRAGMENT_DEFINITION,
27+
self::FRAGMENT_SPREAD => self::FRAGMENT_SPREAD,
28+
self::INLINE_FRAGMENT => self::INLINE_FRAGMENT,
29+
self::VARIABLE_DEFINITION => self::VARIABLE_DEFINITION,
30+
];
31+
2332
const SCHEMA = 'SCHEMA';
2433
const SCALAR = 'SCALAR';
2534
const OBJECT = 'OBJECT';
@@ -32,16 +41,7 @@ class DirectiveLocation
3241
const INPUT_OBJECT = 'INPUT_OBJECT';
3342
const INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION';
3443

35-
/** @var string[] */
36-
private static $locations = [
37-
self::QUERY => self::QUERY,
38-
self::MUTATION => self::MUTATION,
39-
self::SUBSCRIPTION => self::SUBSCRIPTION,
40-
self::FIELD => self::FIELD,
41-
self::FRAGMENT_DEFINITION => self::FRAGMENT_DEFINITION,
42-
self::FRAGMENT_SPREAD => self::FRAGMENT_SPREAD,
43-
self::INLINE_FRAGMENT => self::INLINE_FRAGMENT,
44-
self::VARIABLE_DEFINITION => self::VARIABLE_DEFINITION,
44+
const TYPE_SYSTEM_LOCATIONS = [
4545
self::SCHEMA => self::SCHEMA,
4646
self::SCALAR => self::SCALAR,
4747
self::OBJECT => self::OBJECT,
@@ -55,8 +55,10 @@ class DirectiveLocation
5555
self::INPUT_FIELD_DEFINITION => self::INPUT_FIELD_DEFINITION,
5656
];
5757

58+
const LOCATIONS = self::EXECUTABLE_LOCATIONS + self::TYPE_SYSTEM_LOCATIONS;
59+
5860
public static function has(string $name): bool
5961
{
60-
return isset(self::$locations[$name]);
62+
return isset(self::LOCATIONS[$name]);
6163
}
6264
}

0 commit comments

Comments
 (0)