gql_code_gen 0.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

A package for Dart code generation from GraphQL source.

Includes:

  • package:gql/dart.dart for generating Dart code from GraphQL AST nodes;
  • package:gql/ast_builder.dart for pre-parsing GraphQL into Dart source files.

Usage #

A simple usage example build.yaml:

targets:
  $default:
    builders:
      ast_builder:

The generated source depends on package:gql/ast.dart so you'll need to add it to your pubspec.yaml

dependencies:
  gql: ^0.10.0

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.5 #

  • Support non-standard imports

0.1.4 #

  • Upgrade package:gql to v0.12.0

0.1.3 #

  • Move out example

0.1.2 #

  • Upgrade package:gql to v0.11.0

0.1.1 #

  • Upgrade package:gql to v0.10.0

0.1.0 #

  • Spun off of package:gql

example/gql_code_gen_example.dart

import "package:code_builder/code_builder.dart";
import "package:dart_style/dart_style.dart";
import "package:gql/ast.dart" as ast;
import "package:gql_code_gen/gql_code_gen.dart" as dart;
import "package:gql/language.dart" as lang;
import "package:source_span/source_span.dart";

void main() {
  final ast.DocumentNode docNode = lang.parse(
    SourceFile.fromString(
      """
        query UserInfo(\$id: ID!) {
          user(id: \$id) {
            id
            name
          }
        }
      """,
    ),
  );

  final Expression docExpression = dart.fromNode(
    docNode,
  );

  final library = Library(
    (b) => b.body.add(
      docExpression.assignFinal("document").statement,
    ),
  );

  final formatted = DartFormatter().format(
    "${library.accept(
      DartEmitter.scoped(),
    )}",
  );

  print(formatted);
}

Use this package as a library

1. Depend on it

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


dependencies:
  gql_code_gen: ^0.1.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:gql_code_gen/gql_code_gen.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/gql-dart/gql/tree/master/gql_code_gen was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
build ^1.0.0 1.2.2
code_builder ^3.2.0 3.2.1
collection ^1.14.11 1.14.12
dart_style ^1.2.9 1.3.3
glob ^1.2.0 1.2.0
gql ^0.12.0 0.12.0
meta ^1.1.7 1.1.8
path ^1.6.4 1.6.4
pedantic ^1.0.0 1.9.0
source_span ^1.5.5 1.6.0
Transitive dependencies
_fe_analyzer_shared 1.0.3
analyzer 0.39.4
args 1.5.2
async 2.4.0
built_collection 4.3.2
built_value 7.0.8
charcode 1.1.2
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
fixnum 0.10.11
html 0.14.0+3
js 0.6.1+1
logging 0.11.4
matcher 0.12.6
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0 2.0.0
pub_semver 1.4.2
quiver 2.1.2+1
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_test ^0.10.7
cats
gql_pedantic ^1.0.0
test ^1.0.0