platform/graphql_parser/README.md

48 lines
1.4 KiB
Markdown
Raw Normal View History

2018-08-02 12:48:53 +00:00
# graphql_parser
[![Pub](https://img.shields.io/pub/v/graphql_parser.svg)](https://pub.dartlang.org/packages/graphql_parser)
2018-08-05 00:44:41 +00:00
[![build status](https://travis-ci.org/angel-dart/graphql.svg)](https://travis-ci.org/angel-dart/graphql)
2018-08-02 12:48:53 +00:00
2018-08-05 00:44:41 +00:00
Parses GraphQL queries and schemas.
2018-08-02 12:48:53 +00:00
*This library is merely a parser/visitor*. Any sort of actual GraphQL API functionality must be implemented by you,
or by a third-party package.
[Angel framework](https://angel-dart.github.io)
users should consider
[`package:angel_graphql`](https://pub.dartlang.org/packages/angel_graphql)
as a dead-simple way to add GraphQL functionality to their servers.
# Installation
Add `graphql_parser` as a dependency in your `pubspec.yaml` file:
```yaml
dependencies:
graphql_parser: ^1.0.0
```
# Usage
2019-04-18 14:44:37 +00:00
The AST featured in this library was originally directly based off this ANTLR4 grammar created by Joseph T. McBride:
2018-08-02 12:48:53 +00:00
https://github.com/antlr/grammars-v4/blob/master/graphql/GraphQL.g4
2018-08-05 00:44:41 +00:00
It has since been updated to reflect upon the grammar in the official GraphQL
2019-04-18 14:44:37 +00:00
specification (
[June 2018](https://facebook.github.io/graphql/June2018/)).
2018-08-05 00:44:41 +00:00
2018-08-02 12:48:53 +00:00
```dart
import 'package:graphql_parser/graphql_parser.dart';
doSomething(String text) {
var tokens = scan(text);
2019-08-08 02:24:19 +00:00
var parser = Parser(tokens);
2018-08-02 12:48:53 +00:00
2018-08-05 00:44:41 +00:00
if (parser.errors.isNotEmpty) {
// Handle errors...
}
2018-08-02 12:48:53 +00:00
// Parse the GraphQL document using recursive descent
var doc = parser.parseDocument();
// Do something with the parsed GraphQL document...
}
```