dart_graphql 0.3.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

GraphQL Plugin #

Support for using graphql in Dart.

This plugin defines a simple framework for generating graphql entities.

The code generation is based on a set of graphql queries but all affected types are generated using the original type name and all properties. This behavior allows to use a common type like PageInfo everywhere in your code.

Features #

  • Generate directly from http endpoint
  • Lazy response parsing
  • Case insensitive enum handling

Getting started #

See example project

build.yaml #

Add build.yaml to your project:

targets:
  $default:
    builders:
      example|graphql_builder:
        generate_for:
          - "**/*.graphql"
        options:
          gqlEndpoint: "https://gitlab.com/api/graphql"

builders:
  graphql_builder:
    import: "package:dart_graphql/generator/graphql_fetch_generator.dart"
    builder_factories: ["getGqlBuilder"]
    build_extensions:
      .graphql:
        - .graphql.dart
    auto_apply: dependents
    build_to: source
    applies_builders: ["source_gen"]

gitlab.graphql #

Create a graphql file:

query GitlabCEIssueLabels($firstN: Int) {
  project(fullPath: "gitlab-org/gitlab-ce") {
    id
    issues(first: $firstN) {
      edges {
        node {
          title
          state
          labels {
            edges {
              node {
                title
              }
            }
          }
        }
      }
    }
  }
}

Build #

Run pub run build_runner build --verbose --delete-conflicting-outputs

Use #

import 'package:dart_graphql/dart_graphql.dart';
import 'package:example/gitlab.graphql.dart';

void main() async {
  GraphqlClient gqlClient = GraphqlClient("https://gitlab.com/api/graphql");
  var gqlResponse = await gqlClient.query(GitlabCEIssueLabels(firstN: 15));

  print("Issue labels:");
  for (IssueEdge issueEdge in gqlResponse.data.project.issues.edges) {
    List<String> labels =
        issueEdge.node.labels.edges.map((e) => e.node.title).toList();

    print(
        "${issueEdge.node.title} [${issueEdge.node.state}]: ${labels.join(', ')}");
  }
}

Notes #

The plugin based on graphql-fetch project ported to dart2 and extended.

Please file feature requests and bugs at the issue tracker.

Changelog #

0.3.3 #

  • Fix noSuchMethod error

0.3.2 #

  • Fix cast error during parsing errors
  • More analysis rules

0.3.1 #

  • Remove dart:html dependency so the package can be used without flutter web

0.3.0 #

  • Remove dart:io dependency so the package can be used with flutter web

0.2.2 #

  • Happier pub linter

0.2.1 #

  • Use strict mode and more linter rules
  • Fix an enum encoding issue

0.2.0 #

  • Publish dart_graphql pub

0.0.1 #

  • Initial version

example/README.md

example #

build.yaml #

Add build.yaml to your project:

targets:
  $default:
    builders:
      example|graphql_builder:
        generate_for:
          - "**/*.graphql"
        options:
          gqlEndpoint: "https://gitlab.com/api/graphql"

builders:
  graphql_builder:
    import: "package:dart_graphql/generator/graphql_fetch_generator.dart"
    builder_factories: ["getGqlBuilder"]
    build_extensions:
      .graphql:
        - .graphql.dart
    auto_apply: dependents
    build_to: source
    applies_builders: ["source_gen"]

gitlab.graphql #

Create a graphql file:

query GitlabCEIssueLabels($firstN: Int) {
  project(fullPath: "gitlab-org/gitlab-ce") {
    id
    issues(first: $firstN) {
      edges {
        node {
          title
          state
          labels {
            edges {
              node {
                title
              }
            }
          }
        }
      }
    }
  }
}

Build #

Run pub run build_runner build --verbose --delete-conflicting-outputs

Use #

import 'package:dart_graphql/dart_graphql.dart';
import 'package:example/gitlab.graphql.dart';

void main() async {
  GraphqlClient gqlClient = GraphqlClient("https://gitlab.com/api/graphql");
  var gqlResponse = await gqlClient.query(GitlabCEIssueLabels(firstN: 15));

  print("Issue labels:");
  for (IssueEdge issueEdge in gqlResponse.data.project.issues.edges) {
    List<String> labels =
        issueEdge.node.labels.edges.map((e) => e.node.title).toList();

    print(
        "${issueEdge.node.title} [${issueEdge.node.state}]: ${labels.join(', ')}");
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_graphql: ^0.3.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:dart_graphql/dart_graphql.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
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]
61
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Health issues and suggestions

Document public APIs. (-0.39 points)

188 out of 192 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
async ^2.0.0 2.4.0
build ^1.0.0 1.2.2
build_runner ^1.0.0 1.7.2
code_builder ^3.1.3 3.2.1
dart_style ^1.0.0 1.3.3
graphql_parser ^1.0.0 1.1.4
http ^0.12.0 0.12.0+2
json_object_lite ^2.0.0 2.1.0
meta ^1.0.0 1.1.8
path ^1.0.0 1.6.4
Transitive dependencies
_fe_analyzer_shared 1.0.0
analyzer 0.39.1
args 1.5.2
build_config 0.4.1+1
build_daemon 2.1.2
build_resolvers 1.3.0
build_runner_core 4.2.0
built_collection 4.3.0
built_value 7.0.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
fixnum 0.10.11
front_end 0.1.29
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.29
logging 0.11.3+2
matcher 0.12.6
mime 0.9.6+3
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
package_resolver 1.0.10
pedantic 1.8.0+1
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
shelf 0.7.5
shelf_web_socket 0.2.3
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.20
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.1.6
watcher 0.9.7+12
web_socket_channel 1.1.0
yaml 2.2.0
Dev dependencies
test any