graphql-paths-to-ast

0.2.0 • Public • Published

graphql-paths-to-ast

A function to transform a list of paths to a GraphQL AST

$ yarn add graphql-paths-to-ast

Usage

const pathsToAst = require('graphql-paths-to-ast');

pathsToAst([
  'name',
  'address.city',
  'address.country'
]);

/*
{
  "selections": [
    {
      "name": {
        "value": "name",
        "kind": "Name"
      },
      "kind": "Field"
    },
    {
      "selectionSet": {
        "selections": [
          {
            "name": {
              "value": "city",
              "kind": "Name"
            },
            "kind": "Field"
          },
          {
            "name": {
              "value": "country",
              "kind": "Name"
            },
            "kind": "Field"
          }
        ],
        "kind": "SelectionSet"
      },
      "name": {
        "value": "address",
        "kind": "Name"
      },
      "kind": "Field"
    }
  ],
  "kind": "SelectionSet"
}
*/

const pathsToAst = require('graphql-paths-to-ast');
const {print} = require('graphql')

print(
  pathsToAst([ 'name', 'address.city', 'address.country' ])
);

/*
{
  name
  address {
    city
    country
  }
}
/*

Readme

Keywords

Package Sidebar

Install

npm i graphql-paths-to-ast

Weekly Downloads

2

Version

0.2.0

License

MIT

Last publish

Collaborators

  • imranolas