Completed
Push — master ( fadbb0...7b1f91 )
by Mikaël
21:23 queued 11:51
created

AllTranslationsDirective::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BBSLab\NovaTranslation\GraphQL\Directives;
4
5
use GraphQL\Language\AST\FieldDefinitionNode;
6
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
7
use GraphQL\Type\Definition\ResolveInfo;
8
use Nuwave\Lighthouse\Schema\AST\DocumentAST;
9
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
10
use Nuwave\Lighthouse\Schema\Values\FieldValue;
11
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
12
use Nuwave\Lighthouse\Support\Contracts\FieldResolver;
13
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
14
15
class AllTranslationsDirective extends BaseDirective implements FieldResolver, FieldManipulator
16
{
17
    use Traits\ExtendSchemaWithLocaleFields, Traits\LocaleFilters;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public static function definition(): string
23
    {
24
        return /* @lang GraphQL */ <<<'SDL'
25
directive @allTranslations(
26
  "Specify the class name of the model to use."
27
  model: String
28
  "Specify the GraphQL type to add the 'locale' field (if GraphQL type is different from model class basename)."
29
  type: String
30
) on FIELD_DEFINITION
31
SDL;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function manipulateFieldDefinition(DocumentAST &$documentAST, FieldDefinitionNode &$fieldDefinition, ObjectTypeDefinitionNode &$parentType): void
38
    {
39
        $this->extendSchemaWithLocaleFields(
40
            $documentAST,
41
            $this->directiveArgValue('type', class_basename($this->getModelClass()))
42
        );
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function resolveField(FieldValue $fieldValue): FieldValue
49
    {
50
        return $fieldValue->setResolver(
51
            function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) {
52
                return $resolveInfo
0 ignored issues
show
Bug introduced by
The property argumentSet does not seem to exist in GraphQL\Type\Definition\ResolveInfo.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53
                    ->argumentSet
54
                    ->enhanceBuilder(
55
                        $this->localeFilters($this->getModelClass(), $args),
56
                        $this->directiveArgValue('scopes', [])
57
                    )
58
                    ->get();
59
            }
60
        );
61
    }
62
}
63