gql_code_gen 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new77

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

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]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Oct 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
build ^1.0.0 1.2.0
code_builder ^3.2.0 3.2.0
collection ^1.14.11 1.14.12
dart_style ^1.2.9 1.3.1
gql ^0.11.0 0.11.1
meta ^1.1.7 1.1.7
pedantic ^1.0.0 1.8.0+1
source_span ^1.5.5 1.5.5
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
built_collection 4.2.2
built_value 6.7.1
charcode 1.1.2
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
fixnum 0.10.9
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.27
logging 0.11.3+2
matcher 0.12.5
package_config 1.1.0
path 1.6.4
pub_semver 1.4.2
quiver 2.0.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_test ^0.10.7
cats
gql_pedantic ^1.0.0
test ^1.0.0