Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit af71aad

Browse files
authored
Merge pull request #324 from tuannyharumi/feat/execute-with-context
Accept and return gql context in client's methods
2 parents 795aa7f + 6365901 commit af71aad

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 7.0.0-beta.14
4+
5+
- Support gql context in client's execute and stream methods
6+
37
## 7.0.0-beta.13
48

59
- fix for https://github.com/comigor/artemis/issues/177

lib/client.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,45 @@ class ArtemisClient {
4242

4343
/// Executes a [GraphQLQuery], returning a typed response.
4444
Future<GraphQLResponse<T>> execute<T, U extends JsonSerializable>(
45-
GraphQLQuery<T, U> query,
46-
) async {
45+
GraphQLQuery<T, U> query, {
46+
Context context = const Context(),
47+
}) async {
4748
final request = Request(
4849
operation: Operation(
4950
document: query.document,
5051
operationName: query.operationName,
5152
),
5253
variables: query.getVariablesMap(),
54+
context: context,
5355
);
5456

5557
final response = await _link.request(request).first;
5658

5759
return GraphQLResponse<T>(
5860
data: response.data == null ? null : query.parse(response.data ?? {}),
5961
errors: response.errors,
62+
context: response.context,
6063
);
6164
}
6265

6366
/// Streams a [GraphQLQuery], returning a typed response stream.
6467
Stream<GraphQLResponse<T>> stream<T, U extends JsonSerializable>(
65-
GraphQLQuery<T, U> query,
66-
) {
68+
GraphQLQuery<T, U> query, {
69+
Context context = const Context(),
70+
}) {
6771
final request = Request(
6872
operation: Operation(
6973
document: query.document,
7074
operationName: query.operationName,
7175
),
7276
variables: query.getVariablesMap(),
77+
context: context,
7378
);
7479

7580
return _link.request(request).map((response) => GraphQLResponse<T>(
7681
data: response.data == null ? null : query.parse(response.data ?? {}),
7782
errors: response.errors,
83+
context: response.context,
7884
));
7985
}
8086

lib/schema/graphql_response.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ class GraphQLResponse<T> {
1212
/// If this response has any error.
1313
bool get hasErrors => errors != null && errors!.isNotEmpty;
1414

15+
/// The [Context] of the [Response]
16+
final Context? context;
17+
1518
/// Instantiates a GraphQL response.
1619
const GraphQLResponse({
1720
this.data,
1821
this.errors,
22+
this.context,
1923
});
2024
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: artemis
2-
version: 7.0.0-beta.13
2+
version: 7.0.0-beta.14
33

44
description: Build dart types from GraphQL schemas and queries (using Introspection Query).
55
homepage: https://github.com/comigor/artemis

0 commit comments

Comments
 (0)