graphql_inspector

A Flutter package to intercept and inspect GraphQL API requests and responses β€” inspired by tools like Chucker for Android and Postman. Ideal for debugging GraphQL requests in development builds.

πŸ“ Folder Structure

graphql_inspector/
β”œβ”€β”€ lib/
β”‚   └── src/
β”‚       β”œβ”€β”€ GraphQLLogScreen.dart
β”‚       └── LoggingLink.dart
β”œβ”€β”€ test/
β”œβ”€β”€ README.md
β”œβ”€β”€ pubspec.yaml
β”œβ”€β”€ LICENSE
β”œβ”€β”€ CHANGELOG.md
└── ...

✨ Features

  • πŸ“¦ Logs every GraphQL query, mutation, and variables
  • 🎯 Displays request time and response neatly
  • 🧾 Pretty JSON viewer with syntax highlighting
  • πŸ”„ Export GraphQL requests as cURL commands
  • πŸ“‹ Copy/share requests directly from your Flutter UI
  • πŸ’‘ Useful for QA, debugging, and API development

πŸ“Έ Screenshots

Query View Response View cURL Export
query response curl

πŸš€ Getting Started

1. Add dependency

dependencies:
  graphql_inspector: ^1.0.0

2. Usage

Import the package and wrap your GraphQL client with the LoggingLink. You can then use the GraphQLLogScreen widget to view logged requests and responses in your app.

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:graphql_inspector/graphql_inspector.dart';
import 'package:hive_flutter/hive_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter();

  final httpLink = HttpLink(
    'https://your.graphql.api/graphql',
    defaultHeaders: {'Authorization': 'Bearer YOUR_TOKEN', 'store': 'en_sa'},
  );

  final loggingLink = LoggingLink(
    innerLink: httpLink,
    url: 'https://your.graphql.api/graphql',
    headers: {'Authorization': 'Bearer YOUR_TOKEN', 'store': 'en_sa'},
  );

  final client = GraphQLClient(link: loggingLink, cache: GraphQLCache());

  runApp(MyApp(client: client));
}

class MyApp extends StatelessWidget {
  final GraphQLClient client;
  const MyApp({super.key, required this.client});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('GraphQL Inspector Example')),
        body: Center(
          child: Builder(
            builder: (context) => ElevatedButton(
              child: const Text('Open Inspector'),
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (_) => const GraphQLLogScreen()),
                );
              },
            ),
          ),
        ),
      ),
    );
  }
}

- Replace the API URL and headers with your own.
- Use the `GraphQLLogScreen` widget anywhere in your app to inspect requests and responses.

Libraries

graphql_inspector