An open API service indexing awesome lists of open source software.

https://github.com/imranolas/graphql-paths-to-ast

Transforms a list of object get paths to a GraphQL query
https://github.com/imranolas/graphql-paths-to-ast

ast graphql

Last synced: 5 months ago
JSON representation

Transforms a list of object get paths to a GraphQL query

Awesome Lists containing this project

README

          


graphql-paths-to-ast


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


`$ yarn add graphql-paths-to-ast`

## Usage

```js
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
}
}
/*