graphql_parser 1.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 76

graphql_parser

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.

Installation

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

dependencies:
  graphql_parser: ^1.0.0

Usage

The AST featured in this library is directly based off this ANTLR4 grammar created by Joseph T. McBride: https://github.com/antlr/grammars-v4/blob/master/graphql/GraphQL.g4

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...
}

1.1.1

  • Pubspec updates for Dart 2.

1.1.0

  • 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.

example/example.dart

import 'package:graphql_parser/graphql_parser.dart';

final String text = '''
{
  project(name: "GraphQL") {
    tagline
  }
}
  '''
    .trim();

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(projectField.fieldName.name); // project
  print(projectField.arguments.first.name); // name
  print(projectField.arguments.first.valueOrVariable.value.value); // GraphQL

  var taglineField = projectField.selectionSet.selections.first.field;
  print(taglineField.fieldName.name); // tagline
}

Use this package as a library

1. Depend on it

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


dependencies:
  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
Popularity:
Describes how popular the package is relative to other packages. [more]
66
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
76
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

Platforms

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.

Dependencies

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