src/Schema/AST/ASTHelper.php
public static function attachDirectiveToObjectTypeFields(DocumentAST $documentAST, DirectiveNode $directive): DocumentAST
    {
        return $documentAST->objectTypeDefinitions()
            ->reduce(
                function (DocumentAST $document, ObjectTypeDefinitionNode $objectType) use ($directive): DocumentAST {
                    if (! data_get($objectType, 'name.value')) {
                        return $document;
                    }

                    $objectType->fields = new NodeList(
                        (new Collection($objectType->fields))
                            ->map(function (FieldDefinitionNode $field) use ($directive): FieldDefinitionNode {
                                $field->directives = $field->directives->merge([$directive]);

                                return $field;
                            })
                            ->all()
                    );

                    $document->setDefinition($objectType);

                    return $document;
                },
                $documentAST
            );
    }
public static function attachDirectiveToObjectTypeFields(DocumentAST $documentAST, DirectiveNode $directive): DocumentAST
    {
        return $documentAST->objectTypeDefinitions()
            ->reduce(
                function (DocumentAST $document, ObjectTypeDefinitionNode $objectType) use ($directive): DocumentAST {
                    if (! data_get($objectType, 'name.value')) {
                        return $document;
                    }

                    $objectType->fields = new NodeList(
                        (new Collection($objectType->fields))
                            ->map(function (FieldDefinitionNode $field) use ($directive): FieldDefinitionNode {
                                $field->directives = $field->directives->merge([$directive]);

                                return $field;
                            })
                            ->all()
                    );

                    $document->setDefinition($objectType);

                    return $document;
                },
                $documentAST
            );
    }
public static function attachDirectiveToObjectTypeFields ( DocumentAST $ documentAST , DirectiveNode $ directive ) : DocumentAST { return $ documentAST -> objectTypeDefinitions ( ) -> reduce ( function ( DocumentAST $ document , ObjectTypeDefinitionNode $ objectType ) use ( $ directive ) : DocumentAST { if ( ! data_get ( $ objectType , 'name.value' ) ) { return $ document ; } $ objectType -> fields = new NodeList ( ( new Collection ( $ objectType -> fields ) ) -> map ( function ( FieldDefinitionNode $ field ) use ( $ directive ) : FieldDefinitionNode { $ field -> directives = $ field -> directives -> merge ( [ $ directive ] ) ; return $ field ; } ) -> all ( ) ) ; $ document -> setDefinition ( $ objectType ) ; return $ document ; } , $ documentAST ) ; }
Attach directive to all registered object type fields.

@param  \Nuwave\Lighthouse\Schema\AST\DocumentAST  $documentAST
@param  \GraphQL\Language\AST\DirectiveNode  $directive
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST
Attach directive to all registered object type fields .