graphql_fetch 0.0.3 copy "graphql_fetch: ^0.0.3" to clipboard
graphql_fetch: ^0.0.3 copied to clipboard

a simple graphql client for dart

graphql-fetch #

How to use #

  1. Add dependencies to pubspec.yaml
dependencies:
  graphql_fetch: any
  ...
dev_dependencies:
  graphql_fetch_generator: any
  ...
  1. Create a program tool/build.dart:
import 'dart:async';
import 'package:build_runner/build_runner.dart';
import 'package:graphql_fetch_generator/action.dart';

var action = createBuildAction(
    createSetting(
        schemaUrl: "$schemaUrl"));


Future main() async {
  await build([action], deleteFilesByDefault: true, writeToCache: false);
  // or you can watch file changes;
  // await watch([action]);
}

change $schemaUrl to your graphql schema url address or specify a schema.json file

  1. Put any *.graphql file in your source folder

  2. Run tool/build to generate *.graphql.dart files

  3. use generated code:

import 'package:graphql_fetch/graphql_fetch.dart';
import './query.graphql.dart';  // generated file 

main() {
  String endpoint = "...";

  GraphqlClient client =new GraphqlClient(endpoint);
  // use generated method
  GraphqlResponse<TestResult> result =await client.query(test(first: 5));
  TestResult data = result; // type-safe result
}

example #

1
likes
20
pub points
0%
popularity

Publisher

unverified uploader

a simple graphql client for dart

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

http, meta

More

Packages that depend on graphql_fetch