Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gql_http_link] Add response headers to context #121

Merged
merged 3 commits into from
Jul 9, 2020
Merged
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
4 changes: 4 additions & 0 deletions links/gql_http_link/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.10

- add `headers` to `HttpLinkResponseContext`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that this should be included on a release commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean, should I remove this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is we update the changelog in the change PR, so this is right. @klavs seems we should probably make a more detailed contributor doc.


## 0.2.9

- remove `author` field from `pubspec.yaml`
Expand Down
9 changes: 8 additions & 1 deletion links/gql_http_link/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ class HttpLinkResponseContext extends ContextEntry {
/// HTTP status code of the response
final int statusCode;

/// HTTP response headers
final Map<String, String> headers;

const HttpLinkResponseContext({
@required this.statusCode,
}) : assert(statusCode != null);
@required this.headers,
}) : assert(statusCode != null),
assert(headers != null);

@override
List<Object> get fieldsForEquality => [
statusCode,
headers,
];
}

Expand Down Expand Up @@ -113,6 +119,7 @@ class HttpLink extends Link {
return response.context.withEntry(
HttpLinkResponseContext(
statusCode: httpResponse.statusCode,
headers: httpResponse.headers,
),
);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion links/gql_http_link/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: gql_http_link
version: 0.2.9
version: 0.2.10
description: GQL Terminating Link to execute requests via HTTP using JSON.
repository: https://github.com/gql-dart/gql
environment:
Expand Down
12 changes: 10 additions & 2 deletions links/gql_http_link/test/gql_http_link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void main() {
"data": <String, dynamic>{},
}),
200,
headers: {"header-1": "value-1"},
),
),
);
Expand All @@ -72,7 +73,10 @@ void main() {
ResponseExtensions(null),
)
.withEntry(
HttpLinkResponseContext(statusCode: 200),
HttpLinkResponseContext(
statusCode: 200,
headers: const {"header-1": "value-1"},
),
),
),
emitsDone,
Expand Down Expand Up @@ -361,6 +365,7 @@ void main() {
},
),
200,
headers: {"header-1": "value-1"},
),
),
);
Expand All @@ -385,7 +390,10 @@ void main() {
ResponseExtensions(null),
)
.withEntry(
HttpLinkResponseContext(statusCode: 200),
HttpLinkResponseContext(
statusCode: 200,
headers: const {"header-1": "value-1"},
),
),
),
emitsDone,
Expand Down