graphql_client Build Status

GraphQL Client written in Dart 🎯.

It relies on the dart http client to send GQL queries. As the http client is platform-independent, and can be used on the command-line, browser and Flutter. It has a custom DSL to write GQL queries.


For now, you have to write your GQL queries with the graphql_client DSL. You will be able to convert GQL queries into this DSL soon using a dart transformer.

The following code sample allows you to retrieve the current github user bio using the Github GraphQL API v4.

import 'dart:async';
import 'dart:io'; // Optional because I am reading env variables.

import 'package:http/http.dart';
import 'package:logging/logging.dart'; // Optional
import 'package:graphql_client/graphql_client.dart';
import 'package:graphql_client/graphql_dsl.dart';

 * Define a custom GQL query.
 * The corresponding GQL is :
 * query ViewerBioQuery {
 *   viewer {
 *     bio
 *   }
 * }

class ViewerBioQuery extends Object with Fields implements GQLOperation {
  ViewerResolver viewer = new ViewerResolver();

  String get type => queryType;

  String get name => 'ViewerBioQuery';

  List<GQLField> get fields => [viewer];

  ViewerBioQuery clone() => new ViewerBioQuery()..viewer = viewer.clone();

class ViewerResolver extends Object with Fields implements GQLField {
  BioResolver bio = new BioResolver();

  String get name => 'viewer';

  List<GQLField> get fields => [bio];

  ViewerResolver clone() => new ViewerResolver() = bio.clone();

class BioResolver extends Object with Scalar<String> implements GQLField {
  String get name => 'bio';

  BioResolver clone() => new BioResolver();

Future main() async {
  Logger.root // Optional
    ..level = Level.ALL
    ..onRecord.listen((rec) {
      print('${}: ${rec.time}: ${rec.message}');
  const endPoint = '';
  final apiToken = Platform.environment['GITHUBQL_TOKEN'];

  final client = new Client();
  final logger = new Logger('GQLClient'); // Optional.
  final graphQLClient = new GQLClient(
    client: client,
    logger: logger,
    endPoint: endPoint,

  final query = new ViewerBioQuery();

  try {
    final queryRes = await graphQLClient.execute(
      variables: {},
      headers: {
        'Authorization': 'bearer $apiToken',

    print(; // => 'My awesome Github Bio!'
  } on GQLException catch (e) {


You can find it here.


Support for doing something awesome. [...]
Support for doing something awesome. [...]