https://github.com/imranolas/graphql-ast-types
Functional helpers for working with a GraphQL AST
https://github.com/imranolas/graphql-ast-types
ast graphql-js
Last synced: 5 months ago
JSON representation
Functional helpers for working with a GraphQL AST
- Host: GitHub
- URL: https://github.com/imranolas/graphql-ast-types
- Owner: imranolas
- Created: 2017-10-11T11:08:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:38:44.000Z (over 3 years ago)
- Last Synced: 2025-09-23T23:53:22.611Z (9 months ago)
- Topics: ast, graphql-js
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/graphql-ast-types
- Size: 429 KB
- Stars: 52
- Watchers: 3
- Forks: 6
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
graphql-ast-types
Autogenerated helper functions for generating a GraphQL AST
This project generates helpers functions from the graphql/language AST flow descriptions. It is intended to help with building a valid GraphQL AST.
## Getting Started
`yarn add graphql-ast-types`
```js
import * as t from 'graphql-ast-types';
```
_The implementation here mimics that of `babel-types`. Thanks Babel team._
## Usage
The following is an example of how to build a simple query with AST types.
```js
import * as t from 'graphql-ast-types';
import { print } from 'graphql/language';
const ast = t.document([
t.operationDefinition(
'query',
t.selectionSet([
t.field(t.name('foo')),
t.field(t.name('bar'))
])
)
]);
print(ast);
/*
query {
foo
bar
}
*/
```
In addition, method calls are validated for correctness and accompanied by `is` and `assert` helpers.
```js
t.isName(t.name('Hello')); // true
t.isName({ kind: 'Name' }); // true
t.assert({ kind: 'Name' }); // no error
t.isName({ kind: 'IntValue' }); // false
t.assert({ kind: 'IntValue' }); // error
```
The full API can be found [here](https://github.com/imranolas/graphql-ast-types/blob/master/api.md).