src/Schema/AST/ASTHelper.php
public static function mergeUniqueNodeList($original, $addition, bool $overwriteDuplicates = false): NodeList
    {
        $newNames = (new Collection($addition))
            ->pluck('name.value')
            ->filter()
            ->all();

        $remainingDefinitions = (new Collection($original))
            ->reject(function ($definition) use ($newNames, $overwriteDuplicates): bool {
                $oldName = $definition->name->value;
                $collisionOccurred = in_array(
                    $oldName,
                    $newNames
                );

                if ($collisionOccurred && ! $overwriteDuplicates) {
                    throw new DefinitionException(
                        "Duplicate definition {$oldName} found when merging."
                    );
                }

                return $collisionOccurred;
            })
            ->values()
            ->all();

        return self::mergeNodeList($remainingDefinitions, $addition);
    }
public static function mergeUniqueNodeList($original, $addition, bool $overwriteDuplicates = false): NodeList
    {
        $newNames = (new Collection($addition))
            ->pluck('name.value')
            ->filter()
            ->all();

        $remainingDefinitions = (new Collection($original))
            ->reject(function ($definition) use ($newNames, $overwriteDuplicates): bool {
                $oldName = $definition->name->value;
                $collisionOccurred = in_array(
                    $oldName,
                    $newNames
                );

                if ($collisionOccurred && ! $overwriteDuplicates) {
                    throw new DefinitionException(
                        "Duplicate definition {$oldName} found when merging."
                    );
                }

                return $collisionOccurred;
            })
            ->values()
            ->all();

        return self::mergeNodeList($remainingDefinitions, $addition);
    }
public static function mergeUniqueNodeList ( $ original , $ addition , bool $ overwriteDuplicates = false ) : NodeList { $ newNames = ( new Collection ( $ addition ) ) -> pluck ( 'name.value' ) -> filter ( ) -> all ( ) ; $ remainingDefinitions = ( new Collection ( $ original ) ) -> reject ( function ( $ definition ) use ( $ newNames , $ overwriteDuplicates ) : bool { $ oldName = $ definition -> name -> value ; $ collisionOccurred = in_array ( $ oldName , $ newNames ) ; if ( $ collisionOccurred && ! $ overwriteDuplicates ) { throw new DefinitionException ( "Duplicate definition {$oldName} found when merging." ) ; } return $ collisionOccurred ; } ) -> values ( ) -> all ( ) ; return self :: mergeNodeList ( $ remainingDefinitions , $ addition ) ; }
This function will merge two lists uniquely by name.

@param  \GraphQL\Language\AST\NodeList|array  $original
@param  \GraphQL\Language\AST\NodeList|array  $addition
@param  bool  $overwriteDuplicates By default this throws if a collision occurs. If
this is set to true, the fields of the original list will be overwritten.
@return \GraphQL\Language\AST\NodeList
This function will merge two lists uniquely by name .