graphql-ast-tools
v0.2.3
Published
Tools for the GraphQL Abstract Syntax Tree
Downloads
112
Readme
graphql-ast-tools
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)