@graphql-tools/merge

  • Version 8.3.6
  • Published
  • 94.5 kB
  • 2 dependencies
  • MIT license

Install

npm i @graphql-tools/merge
yarn add @graphql-tools/merge
pnpm add @graphql-tools/merge

Overview

A set of utils for faster development of GraphQL tools

Index

Variables

variable schemaDefSymbol

const schemaDefSymbol: string;

    Functions

    function applyExtensions

    applyExtensions: (
    schema: GraphQLSchema,
    extensions: SchemaExtensions
    ) => GraphQLSchema;

      function defaultStringComparator

      defaultStringComparator: (
      a: string | undefined,
      b: string | undefined
      ) => CompareVal;

        function extractType

        extractType: (type: TypeNode) => NamedTypeNode;

          function isListTypeNode

          isListTypeNode: (type: TypeNode) => type is ListTypeNode;

            function isNamedDefinitionNode

            isNamedDefinitionNode: (
            definitionNode: DefinitionNode
            ) => definitionNode is NamedDefinitionNode;

              function isNonNullTypeNode

              isNonNullTypeNode: (type: TypeNode) => type is NonNullTypeNode;

                function isSourceTypes

                isSourceTypes: (types: any) => types is Source;

                  function isStringTypes

                  isStringTypes: (types: any) => types is string;

                    function isWrappingTypeNode

                    isWrappingTypeNode: (type: TypeNode) => type is any;

                      function mergeArguments

                      mergeArguments: (
                      args1: InputValueDefinitionNode[],
                      args2: InputValueDefinitionNode[],
                      config?: Config
                      ) => InputValueDefinitionNode[];

                        function mergeDirective

                        mergeDirective: (
                        node: DirectiveDefinitionNode,
                        existingNode?: DirectiveDefinitionNode
                        ) => DirectiveDefinitionNode;

                          function mergeDirectives

                          mergeDirectives: (
                          d1?: ReadonlyArray<DirectiveNode>,
                          d2?: ReadonlyArray<DirectiveNode>,
                          config?: Config
                          ) => DirectiveNode[];

                            function mergeEnum

                            mergeEnum: (
                            e1: EnumTypeDefinitionNode | EnumTypeExtensionNode,
                            e2: EnumTypeDefinitionNode | EnumTypeExtensionNode,
                            config?: Config
                            ) => EnumTypeDefinitionNode | EnumTypeExtensionNode;

                              function mergeEnumValues

                              mergeEnumValues: (
                              first: ReadonlyArray<EnumValueDefinitionNode> | undefined,
                              second: ReadonlyArray<EnumValueDefinitionNode> | undefined,
                              config?: Config
                              ) => EnumValueDefinitionNode[];

                                function mergeExtensions

                                mergeExtensions: (extensions: SchemaExtensions[]) => SchemaExtensions;

                                  function mergeFields

                                  mergeFields: <T extends unknown>(
                                  type: { name: NameNode },
                                  f1: ReadonlyArray<T> | undefined,
                                  f2: ReadonlyArray<T> | undefined,
                                  config?: Config
                                  ) => T[];

                                    function mergeGraphQLNodes

                                    mergeGraphQLNodes: (
                                    nodes: ReadonlyArray<DefinitionNode>,
                                    config?: Config
                                    ) => MergedResultMap;

                                      function mergeGraphQLTypes

                                      mergeGraphQLTypes: (typeSource: TypeSource, config: Config) => DefinitionNode[];

                                        function mergeInputType

                                        mergeInputType: (
                                        node: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode,
                                        existingNode: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode,
                                        config?: Config
                                        ) => InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode;

                                          function mergeInterface

                                          mergeInterface: (
                                          node: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode,
                                          existingNode: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode,
                                          config?: Config
                                          ) => InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;

                                            function mergeNamedTypeArray

                                            mergeNamedTypeArray: (
                                            first?: ReadonlyArray<NamedTypeNode>,
                                            second?: ReadonlyArray<NamedTypeNode>,
                                            config?: Config
                                            ) => NamedTypeNode[];

                                              function mergeResolvers

                                              mergeResolvers: <TSource, TContext>(
                                              resolversDefinitions:
                                              | Maybe<IResolvers<TSource, TContext>>
                                              | Maybe<Maybe<IResolvers<TSource, TContext>>[]>,
                                              options?: MergeResolversOptions
                                              ) => IResolvers<TSource, TContext>;
                                              • Deep merges multiple resolver definition objects into a single definition.

                                                Parameter resolversDefinitions

                                                Resolver definitions to be merged

                                                Parameter options

                                                Additional options

                                                const { mergeResolvers } = require('@graphql-tools/merge');
                                                const clientResolver = require('./clientResolver');
                                                const productResolver = require('./productResolver');
                                                const resolvers = mergeResolvers([
                                                clientResolver,
                                                productResolver,
                                                ]);

                                                If you don't want to manually create the array of resolver objects, you can also use this function along with loadFiles:

                                                const path = require('path');
                                                const { mergeResolvers } = require('@graphql-tools/merge');
                                                const { loadFilesSync } = require('@graphql-tools/load-files');
                                                const resolversArray = loadFilesSync(path.join(__dirname, './resolvers'));
                                                const resolvers = mergeResolvers(resolversArray)

                                              function mergeScalar

                                              mergeScalar: (
                                              node: ScalarTypeDefinitionNode | ScalarTypeExtensionNode,
                                              existingNode: ScalarTypeDefinitionNode | ScalarTypeExtensionNode,
                                              config?: Config
                                              ) => ScalarTypeDefinitionNode | ScalarTypeExtensionNode;

                                                function mergeType

                                                mergeType: (
                                                node: ObjectTypeDefinitionNode | ObjectTypeExtensionNode,
                                                existingNode: ObjectTypeDefinitionNode | ObjectTypeExtensionNode,
                                                config?: Config
                                                ) => ObjectTypeDefinitionNode | ObjectTypeExtensionNode;

                                                  function mergeTypeDefs

                                                  mergeTypeDefs: {
                                                  (typeSource: TypeSource): DocumentNode;
                                                  (
                                                  typeSource: TypeSource,
                                                  config?: Partial<Config> & { commentDescriptions: true }
                                                  ): string;
                                                  (
                                                  typeSource: TypeSource,
                                                  config?: Omit<Partial<Config>, 'commentDescriptions'>
                                                  ): DocumentNode;
                                                  };
                                                  • Merges multiple type definitions into a single DocumentNode

                                                    Parameter types

                                                    The type definitions to be merged

                                                  function mergeUnion

                                                  mergeUnion: (
                                                  first: UnionTypeDefinitionNode | UnionTypeExtensionNode,
                                                  second: UnionTypeDefinitionNode | UnionTypeExtensionNode,
                                                  config?: Config
                                                  ) => UnionTypeDefinitionNode | UnionTypeExtensionNode;

                                                    function printTypeNode

                                                    printTypeNode: (type: TypeNode) => string;

                                                      Interfaces

                                                      interface Config

                                                      interface Config extends ParseOptions, GetDocumentNodeFromSchemaOptions {}

                                                        property commentDescriptions

                                                        commentDescriptions?: boolean;
                                                        • Descriptions are defined as preceding string literals, however an older experimental version of the SDL supported preceding comments as descriptions. Set to true to enable this deprecated behavior. This option is provided to ease adoption and will be removed in v16.

                                                          Default: false

                                                        property consistentEnumMerge

                                                        consistentEnumMerge?: boolean;

                                                          property convertExtensions

                                                          convertExtensions?: boolean;

                                                            property exclusions

                                                            exclusions?: string[];

                                                              property forceSchemaDefinition

                                                              forceSchemaDefinition?: boolean;
                                                              • Creates schema definition, even when no types are available Produces: schema { query: Query }

                                                                Default: false

                                                              property ignoreFieldConflicts

                                                              ignoreFieldConflicts?: boolean;

                                                                property reverseDirectives

                                                                reverseDirectives?: boolean;
                                                                • Puts the next directive first.

                                                                  Default: false

                                                                  @example: Given:

                                                                  type User { a: String @foo }
                                                                  type User { a: String @bar }

                                                                  Results:

                                                                  type User { a: @bar @foo }

                                                                property sort

                                                                sort?: boolean | CompareFn<string>;

                                                                  property throwOnConflict

                                                                  throwOnConflict?: boolean;
                                                                  • Throws an error on a merge conflict

                                                                    Default: false

                                                                  property useSchemaDefinition

                                                                  useSchemaDefinition?: boolean;
                                                                  • Produces schema { query: ..., mutation: ..., subscription: ... }

                                                                    Default: true

                                                                  interface MergeResolversOptions

                                                                  interface MergeResolversOptions {}
                                                                  • Additional options for merging resolvers

                                                                  property exclusions

                                                                  exclusions?: string[];

                                                                    Enums

                                                                    enum CompareVal

                                                                    enum CompareVal {
                                                                    A_SMALLER_THAN_B = -1,
                                                                    A_EQUALS_B = 0,
                                                                    A_GREATER_THAN_B = 1,
                                                                    }

                                                                      member A_EQUALS_B

                                                                      A_EQUALS_B = 0

                                                                        member A_GREATER_THAN_B

                                                                        A_GREATER_THAN_B = 1

                                                                          member A_SMALLER_THAN_B

                                                                          A_SMALLER_THAN_B = -1

                                                                            Type Aliases

                                                                            type CompareFn

                                                                            type CompareFn<T> = (a: T | undefined, b: T | undefined) => -1 | 0 | 1;

                                                                              type MergedResultMap

                                                                              type MergedResultMap = Record<string, NamedDefinitionNode> & {
                                                                              [schemaDefSymbol]: SchemaDefinitionNode | SchemaExtensionNode;
                                                                              };

                                                                                Package Files (17)

                                                                                Dependencies (2)

                                                                                Dev Dependencies (0)

                                                                                No dev dependencies.

                                                                                Peer Dependencies (1)

                                                                                Badge

                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@graphql-tools/merge.

                                                                                • Markdown
                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@graphql-tools/merge)
                                                                                • HTML
                                                                                  <a href="https://www.jsdocs.io/package/@graphql-tools/merge"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>