Completed
Pull Request — master (#45)
by Christoffer
02:23
created

undefinedFieldMessage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 4
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
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 (count($suggestedTypeNames) !== 0) {
32
        return $message . ' ' . sprintf(
33
                'Did you mean to use an inline fragment on %s?',
34
                quotedOrList($suggestedTypeNames)
35
            );
36
    }
37
    if (count($suggestedFieldNames) !== 0) {
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 inlineFragmentOnNonCompositeErrorMessage(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