gql_code_gen 0.1.5 copy "gql_code_gen: ^0.1.5" to clipboard
gql_code_gen: ^0.1.5 copied to clipboard

discontinued

GraphQL code generator and file builder for Dart taking *.graphql files as an input.

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);
}
11
likes
25
pub points
36%
popularity

Publisher

verified publishergql-dart.dev

GraphQL code generator and file builder for Dart taking *.graphql files as an input.

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

build, code_builder, collection, dart_style, glob, gql, meta, path, pedantic, source_span

More

Packages that depend on gql_code_gen