Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

spacedragon/graphql-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages