Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/talker/lib/src/talker_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ abstract class TalkerKey {
static const grpcResponse = 'grpc-response';
static const grpcError = 'grpc-error';

/// GraphQL section
static const graphqlRequest = 'graphql-request';
static const graphqlResponse = 'graphql-response';
static const graphqlError = 'graphql-error';
static const graphqlSubscription = 'graphql-subscription';

/// Flutter section
static const route = 'route';

Expand Down
46 changes: 46 additions & 0 deletions packages/talker_graphql_logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

pubspec.lock
pubspec_overrides.yaml
11 changes: 11 additions & 0 deletions packages/talker_graphql_logger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 5.1.1

- Initial release
- Added `TalkerGraphQLLink` for logging GraphQL operations
- Support for queries, mutations, and subscriptions
- Configurable logging settings
- Request/response duration tracking
- Variable obfuscation for sensitive fields
- Custom pen colors for request/response/error logs
21 changes: 21 additions & 0 deletions packages/talker_graphql_logger/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Stanislav Ilin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
181 changes: 181 additions & 0 deletions packages/talker_graphql_logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# talker_graphql_logger

Lightweight and customizable GraphQL client logger on [talker](https://pub.dev/packages/talker) base.

## Preview

<img src="https://github.com/Frezyx/talker/blob/master/docs/assets/talker_graphql_logger/preview.png?raw=true" alt="talker_graphql_logger preview" width="600">

## Getting started

Add the following dependencies to your `pubspec.yaml`:

```yaml
dependencies:
talker: ^5.1.1
talker_graphql_logger: ^5.1.1
graphql: ^5.2.3 # or gql packages
```

## Usage

### Basic Setup

```dart
import 'package:talker/talker.dart';
import 'package:talker_graphql_logger/talker_graphql_logger.dart';
import 'package:gql_link/gql_link.dart';
import 'package:gql_http_link/gql_http_link.dart';

void main() {
// Create talker instance
final talker = Talker();

// Create TalkerGraphQLLink
final talkerLink = TalkerGraphQLLink(talker: talker);

// Create HTTP link
final httpLink = HttpLink('https://api.example.com/graphql');

// Compose links
final link = Link.from([
talkerLink,
httpLink,
]);

// Use the link with your GraphQL client
}
```

### With graphql_flutter package

```dart
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talker/talker.dart';
import 'package:talker_graphql_logger/talker_graphql_logger.dart';

void main() async {
await initHiveForFlutter();

final talker = Talker();

final talkerLink = TalkerGraphQLLink(talker: talker);
final httpLink = HttpLink('https://api.example.com/graphql');

final link = Link.from([talkerLink, httpLink]);

final client = GraphQLClient(
link: link,
cache: GraphQLCache(store: HiveStore()),
);
}
```

## Customization

### Settings

```dart
final talkerLink = TalkerGraphQLLink(
talker: talker,
settings: TalkerGraphQLLoggerSettings(
// Enable/disable logging
enabled: true,

// Log level for GraphQL logs
logLevel: LogLevel.debug,

// Print variables in request logs
printVariables: true,

// Print response data
printResponse: true,

// Print GraphQL query string (can be large)
printQuery: false,

// Maximum length of response data to print
responseMaxLength: 2000,

// Fields to obfuscate in variables
obfuscateFields: {'password', 'token', 'apiKey'},

// Custom colors for different log types
requestPen: AnsiPen()..xterm(219),
responsePen: AnsiPen()..xterm(46),
errorPen: AnsiPen()..red(),
subscriptionPen: AnsiPen()..cyan(),
),
);
```

### Filtering

```dart
final talkerLink = TalkerGraphQLLink(
talker: talker,
settings: TalkerGraphQLLoggerSettings(
// Filter which requests to log
requestFilter: (request) {
// Don't log introspection queries
final operationName = request.operation.operationName;
return operationName != 'IntrospectionQuery';
},

// Filter which responses to log
responseFilter: (request, response) {
return true; // Log all responses
},

// Filter which errors to log
errorFilter: (request, response, error) {
return true; // Log all errors
},
),
);
```

## Features

- ✅ Logs queries, mutations, and subscriptions
- ✅ Request/response duration tracking
- ✅ Variable obfuscation for sensitive data
- ✅ Customizable log colors
- ✅ Request/response/error filtering
- ✅ Truncation for large responses
- ✅ GraphQL error details with path and locations
- ✅ Network error handling

## Log Types

The logger creates the following log types:

| Log Type | TalkerKey | Description |
|----------|-----------|-------------|
| `GraphQLRequestLog` | `graphql-request` | Outgoing GraphQL request |
| `GraphQLResponseLog` | `graphql-response` | Successful response |
| `GraphQLErrorLog` | `graphql-error` | GraphQL or network errors |
| `GraphQLSubscriptionLog` | `graphql-subscription` | Subscription events |

## Integration with TalkerFlutter

Use with [talker_flutter](https://pub.dev/packages/talker_flutter) to view logs in a beautiful UI:

```dart
import 'package:talker_flutter/talker_flutter.dart';

// Navigate to logs screen
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TalkerScreen(talker: talker),
),
);
```

## Additional information

- [Talker documentation](https://github.com/Frezyx/talker)
- [GraphQL package](https://pub.dev/packages/graphql)
- [GQL packages](https://pub.dev/packages/gql)

For issues and feature requests, please visit the [GitHub repository](https://github.com/Frezyx/talker/issues).
31 changes: 31 additions & 0 deletions packages/talker_graphql_logger/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

linter:
rules:
- prefer_relative_imports
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Loading