graphql_parser 1.1.1

  • Example
  • Installing
  • Versions
  • 76


Pub build status

Parses GraphQL queries and schemas.

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 users should consider package:angel_graphql as a dead-simple way to add GraphQL functionality to their servers.


Add graphql_parser as a dependency in your pubspec.yaml file:

  graphql_parser: ^1.0.0


The AST featured in this library is directly based off this ANTLR4 grammar created by Joseph T. McBride:

It has since been updated to reflect upon the grammar in the official GraphQL specification.

import 'package:graphql_parser/graphql_parser.dart';

doSomething(String text) {
  var tokens = scan(text);
  var parser = new Parser(tokens);
  if (parser.errors.isNotEmpty) {
    // Handle errors...
  // Parse the GraphQL document using recursive descent
  var doc = parser.parseDocument();
  // Do something with the parsed GraphQL document...


  • Pubspec updates for Dart 2.


  • Removed GraphQLVisitor.
  • Enable parsing operations without an explicit name.
  • Parse null.
  • Completely ignore commas.
  • Ignore Unicode BOM, as per the spec.
  • Parse object values.
  • Parse enum values.


import 'package:graphql_parser/graphql_parser.dart';

final String text = '''
  project(name: "GraphQL") {

main() {
  var tokens = scan(text);
  var parser = new Parser(tokens);
  var doc = parser.parseDocument();

  var operation = doc.definitions.first as OperationDefinitionContext;

  var projectField = operation.selectionSet.selections.first.field;
  print(; // project
  print(; // name
  print(projectField.arguments.first.valueOrVariable.value.value); // GraphQL

  var taglineField = projectField.selectionSet.selections.first.field;
  print(; // tagline

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  graphql_parser: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:graphql_parser/graphql_parser.dart';
Version Uploaded Documentation Archive
1.1.1 Oct 23, 2018 Go to the documentation of graphql_parser 1.1.1 Download graphql_parser 1.1.1 archive
1.1.0 Aug 5, 2018 Go to the documentation of graphql_parser 1.1.0 Download graphql_parser 1.1.0 archive
1.0.0+1 Jul 5, 2017 Go to the documentation of graphql_parser 1.0.0+1 Download graphql_parser 1.0.0+1 archive
1.0.0 Jul 4, 2017 Go to the documentation of graphql_parser 1.0.0 Download graphql_parser 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:graphql_parser/graphql_parser.dart.

Health issues and suggestions

Document public APIs (-9.92 points)

240 out of 242 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
charcode ^1.0.0 1.1.2
source_span ^1.0.0 1.4.1
string_scanner ^1.0.0 1.0.4
Transitive dependencies
meta 1.1.6
path 1.6.2
Dev dependencies
matcher any
test >=0.12.0 <2.0.0