0.2.3 • Published 6 years ago

graphql-ast-tools v0.2.3

Weekly downloads
133
License
Apache-2.0
Repository
github
Last release
6 years ago

graphql-ast-tools

NPM Version Widget Build Status Widget Coverage Widget

graphql-ast-tools contains a set of methods to help simplifying a GraphQL Document Node by resolving @skip and @include Directives and merging Named Fragments into fields or turning them into Inline Fragments. The goal is to turn a complex document structure with deeply nested fragments into a simpler and shallow one that makes processing easier.

API

/**
 * Options used in transformDocment
 */
interface TransformDocumentOptions {

  // If given, transformDocument will also resolve @include and @skip directives.
  variables?: { [name: string]: any };

  // If given, transformDocument can do a better job at reducing the document.
  typeGetter?: TypeGetter;

  // If given, transformDocument will use fragments from this map. If it does
  // not exist, it will try to find it in the DocumentNode and put it into the map.
  // You can pass the same fragmentMap to multiple transformDocument operations to reduce
  // time required to process fragments.
  fragmentMap?: { [name: string]: DocumentNode };
}

/**
 * transformDocument will resolve NamedFragments and turn them into shallow InlineFragments or if possible
 * merge them directly with Field nodes. If `options.variables` are given it also resolves @include
 * and @skip directives.
 */
function transformDocument(document: DocumentNode, options: TransformDocumentOptions = {}): DocumentNode
/**
 * TypeGetter which is used in `transformDocument`.
 * Passing a path should return its type and implementing types.
 *
 * Examples:
 * query.users.name => ["String"]
 * query.users => ["User"]
 * query.users.flagAction => ["FlagAction", "Action"]
 * query => ["RootQuery"]
 *
 * Special case `type` followed by a type name will
 * resolve starting from that type, e.g.:
 * type.User.name => ["String"]
 * type.RootQuery.users = ["User"]
 */
type TypeGetter = (path: string) => string[];

function createTypeGetter(introspectionData): TypeGetter
/**
 * Merge 2 definitions.
 *
 * B overwrites A if it does not have an selection set.
 * Otherwise merge selection sets.
 */
function mergeDefinitions(a, b)

/**
 * Merge selectionSets.
 */
function mergeSelectionSets(a, b)
0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago