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
- Host: GitHub
- URL: https://github.com/imranolas/graphql-paths-to-ast
- Owner: imranolas
- License: mit
- Created: 2017-10-18T08:47:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:50:53.000Z (over 3 years ago)
- Last Synced: 2025-09-19T01:13:59.296Z (9 months ago)
- Topics: ast, graphql
- Language: JavaScript
- Size: 287 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
}
}
/*