mk_graphql 0.0.5 copy "mk_graphql: ^0.0.5" to clipboard
mk_graphql: ^0.0.5 copied to clipboard

GraphQL client created using dio as http client for more customization for every requests and cancel request.

example/lib/main.dart

import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:mk_graphql/mk_graphql.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void initState() {
    super.initState();
    _request();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  void _request() async {
    final client = GraphClient(
      GraphBaseOptions.fromBaseUrl('https://countries.trevorblades.com'),
      debug: true,
    );
    final response = await client.request(GraphRequest.fromString(_query));
    response.when(
      success: ((data, context, extensions) {
        log('data $data');
        log('context $context');
        log('extensions $extensions');
      }),
      error: (exception) {
        log('exception $exception');
      },
    );
  }
}

const _query = r'''
    {
  countries {
    code
    continent {
      code
      name
    }
  }
}''';

// ignore: unused_element
const _mutation = r'''
mutation Insert_users($objects: [users_insert_input!]!) {
  insert_users(objects: $objects) {
    returning {
      id
      name
    }
  }
}
''';
1
likes
130
points
58
downloads

Publisher

verified publisherkishormainali.com

Weekly Downloads

GraphQL client created using dio as http client for more customization for every requests and cancel request.

Homepage
Repository (GitHub)

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

dio, dio_cache_interceptor, dio_http2_adapter, freezed_annotation, gql, gql_exec, json_annotation

More

Packages that depend on mk_graphql