Skip to content

Commit 16e8ca4

Browse files
feat(graphql): add tracer to the core library to be able to trace the lib
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 6a013af commit 16e8ca4

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

packages/graphql/lib/src/core/query_manager.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:graphql/src/utilities/response.dart';
4+
import 'package:graphql_common/graphql_common.dart';
45
import 'package:meta/meta.dart';
56
import 'package:collection/collection.dart';
67

@@ -26,6 +27,7 @@ class QueryManager {
2627
QueryManager({
2728
required this.link,
2829
required this.cache,
30+
this.tracer,
2931
this.alwaysRebroadcast = false,
3032
}) {
3133
scheduler = QueryScheduler(
@@ -50,6 +52,10 @@ class QueryManager {
5052
/// prevents rebroadcasting for some intensive bulk operation like [refetchSafeQueries]
5153
bool rebroadcastLocked = false;
5254

55+
/// Custom Tracer specified by the user to trace the library
56+
/// if the user need it.
57+
final Tracer? tracer;
58+
5359
ObservableQuery<TParsed> watchQuery<TParsed>(
5460
WatchQueryOptions<TParsed> options) {
5561
final ObservableQuery<TParsed> observableQuery = ObservableQuery<TParsed>(

packages/graphql/lib/src/graphql_client.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import 'package:meta/meta.dart';
22
import 'dart:async';
3-
43
import 'package:graphql/src/core/core.dart';
54
import 'package:graphql/src/cache/cache.dart';
6-
75
import 'package:graphql/src/core/fetch_more.dart';
6+
import 'package:graphql_common/graphql_common.dart';
87

98
/// Universal GraphQL Client with configurable caching and [link][] system.
109
/// modelled after the [`apollo-client`][ac].
@@ -24,12 +23,14 @@ class GraphQLClient implements GraphQLDataProxy {
2423
GraphQLClient({
2524
required this.link,
2625
required this.cache,
26+
this.tracer,
2727
DefaultPolicies? defaultPolicies,
2828
bool alwaysRebroadcast = false,
2929
}) : defaultPolicies = defaultPolicies ?? DefaultPolicies(),
3030
queryManager = QueryManager(
3131
link: link,
3232
cache: cache,
33+
tracer: tracer,
3334
alwaysRebroadcast: alwaysRebroadcast,
3435
);
3536

@@ -44,11 +45,16 @@ class GraphQLClient implements GraphQLDataProxy {
4445

4546
late final QueryManager queryManager;
4647

48+
/// Custom Tracer specified by the user to trace the library
49+
/// if the user need it.
50+
final Tracer? tracer;
51+
4752
/// Create a copy of the client with the provided information.
4853
GraphQLClient copyWith(
4954
{Link? link,
5055
GraphQLCache? cache,
5156
DefaultPolicies? defaultPolicies,
57+
Tracer? tracer,
5258
bool? alwaysRebroadcast}) {
5359
return GraphQLClient(
5460
link: link ?? this.link,

packages/graphql/lib/src/links/websocket_link/websocket_client.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:gql_exec/gql_exec.dart';
77
import 'package:graphql/src/core/query_options.dart' show WithType;
88
import 'package:graphql/src/links/gql_links.dart';
99
import 'package:graphql/src/utilities/platform.dart';
10+
import 'package:graphql_common/graphql_common.dart';
1011
import 'package:meta/meta.dart';
1112
import 'package:rxdart/rxdart.dart';
1213
import 'package:stream_channel/stream_channel.dart';
@@ -48,8 +49,13 @@ class SocketClientConfig {
4849
this.initialPayload,
4950
this.headers,
5051
this.connectFn,
52+
this.tracer,
5153
});
5254

55+
/// Custom Tracer specified by the user to trace the library
56+
/// if the user need it.
57+
final Tracer? tracer;
58+
5359
/// Serializer used to serialize request
5460
final RequestSerializer serializer;
5561

packages/graphql/lib/src/links/websocket_link/websocket_link.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:gql_exec/gql_exec.dart';
22
import 'package:gql_link/gql_link.dart';
3+
import 'package:graphql_common/graphql_common.dart';
34

45
import './websocket_client.dart';
56

@@ -17,6 +18,7 @@ class WebSocketLink extends Link {
1718
this.url, {
1819
this.config = const SocketClientConfig(),
1920
this.subProtocol = GraphQLProtocol.graphqlWs,
21+
this.tracer,
2022
});
2123

2224
final String url;
@@ -26,6 +28,10 @@ class WebSocketLink extends Link {
2628
// cannot be final because we're changing the instance upon a header change.
2729
SocketClient? _socketClient;
2830

31+
/// Custom Tracer specified by the user to trace the library
32+
/// if the user need it.
33+
final Tracer? tracer;
34+
2935
@override
3036
Stream<Response> request(Request request, [forward]) async* {
3137
if (_socketClient == null) {

packages/graphql/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies:
2222
stream_channel: ^2.1.0
2323
rxdart: ^0.27.1
2424
uuid: ^3.0.1
25+
graphql_common:
26+
path: ../graphql_common
2527

2628
dev_dependencies:
2729
async: ^2.5.0

0 commit comments

Comments
 (0)