GithubHelp home page GithubHelp logo

willemmanuel / graphql-ast-tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coralproject/graphql-ast-tools

0.0 0.0 0.0 139 KB

Tools for the GraphQL Abstract Syntax Tree

License: Other

JavaScript 0.86% TypeScript 99.14%

graphql-ast-tools's Introduction

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)

graphql-ast-tools's People

Contributors

cvle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.