|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Validation\Rule; |
|
4
|
|
|
|
|
5
|
|
|
use Digia\GraphQL\Type\Definition\TypeInterface; |
|
6
|
|
|
use function Digia\GraphQL\Util\quotedOrList; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @param string $definitionName |
|
10
|
|
|
* @return string |
|
11
|
|
|
*/ |
|
12
|
|
|
function nonExecutableDefinitionMessage(string $definitionName): string |
|
13
|
|
|
{ |
|
14
|
|
|
return sprintf('The %s definition is not executable.', $definitionName); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $fieldName |
|
19
|
|
|
* @param string $type |
|
20
|
|
|
* @param array $suggestedTypeNames |
|
21
|
|
|
* @param array $suggestedFieldNames |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
function undefinedFieldMessage( |
|
25
|
|
|
string $fieldName, |
|
26
|
|
|
string $type, |
|
27
|
|
|
array $suggestedTypeNames, |
|
28
|
|
|
array $suggestedFieldNames |
|
29
|
|
|
): string { |
|
30
|
|
|
$message = sprintf('Cannot query field "%s" on type "%s".', $fieldName, $type); |
|
31
|
|
|
if (!empty($suggestedTypeNames)) { |
|
32
|
|
|
return $message . ' ' . sprintf( |
|
33
|
|
|
'Did you mean to use an inline fragment on %s?', |
|
34
|
|
|
quotedOrList($suggestedTypeNames) |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
if (!empty($suggestedFieldNames)) { |
|
38
|
|
|
return $message . ' ' . sprintf('Did you mean %s?', quotedOrList($suggestedFieldNames)); |
|
39
|
|
|
} |
|
40
|
|
|
return $message; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param TypeInterface $type |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
function inlineFragmentOnNonCompositeMessage(string $typeName): string |
|
48
|
|
|
{ |
|
49
|
|
|
return sprintf('Fragment cannot condition on non composite type "%s".', $typeName); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $fragmentName |
|
54
|
|
|
* @param string $typeName |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
function fragmentOnNonCompositeMessage(string $fragmentName, string $typeName): string |
|
58
|
|
|
{ |
|
59
|
|
|
return sprintf('Fragment "%s" cannot condition on non composite type "%s".', $fragmentName, $typeName); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $argumentName |
|
64
|
|
|
* @param string $fieldName |
|
65
|
|
|
* @param string $typeName |
|
66
|
|
|
* @param array $suggestedArguments |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
function unknownArgumentMessage( |
|
70
|
|
|
string $argumentName, |
|
71
|
|
|
string $fieldName, |
|
72
|
|
|
string $typeName, |
|
73
|
|
|
array $suggestedArguments |
|
74
|
|
|
): string { |
|
75
|
|
|
$message = sprintf('Unknown argument "%s" on field "%s" of type "%s".', $argumentName, $fieldName, $typeName); |
|
76
|
|
|
if (!empty($suggestedArguments)) { |
|
77
|
|
|
return $message . ' ' . sprintf('Did you mean %s', quotedOrList($suggestedArguments)); |
|
78
|
|
|
} |
|
79
|
|
|
return $message; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $argumentName |
|
84
|
|
|
* @param string $directiveName |
|
85
|
|
|
* @param array $suggestedArguments |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
function unknownDirectiveArgumentMessage(string $argumentName, string $directiveName, array $suggestedArguments): string |
|
89
|
|
|
{ |
|
90
|
|
|
$message = sprintf('Unknown argument "%s" on directive "@%s".', $argumentName, $directiveName); |
|
91
|
|
|
if (!empty($suggestedArguments)) { |
|
92
|
|
|
return $message . ' ' . sprintf('Did you mean %s', quotedOrList($suggestedArguments)); |
|
93
|
|
|
} |
|
94
|
|
|
return $message; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $directiveName |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
function unknownDirectiveMessage(string $directiveName): string |
|
102
|
|
|
{ |
|
103
|
|
|
return sprintf('Unknown directive "%s".', $directiveName); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param string $directiveName |
|
108
|
|
|
* @param string $location |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
function misplacedDirectiveMessage(string $directiveName, string $location): string |
|
112
|
|
|
{ |
|
113
|
|
|
return sprintf('Directive "%s" may not be used on %s.', $directiveName, $location); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param string $fragmentName |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
function unknownFragmentMessage(string $fragmentName): string |
|
121
|
|
|
{ |
|
122
|
|
|
return sprintf('Unknown fragment "%s".', $fragmentName); |
|
123
|
|
|
} |
|
124
|
|
|
|