-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f6a63c
commit 67ed912
Showing
4 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:ferry/ferry.dart'; | ||
import 'package:ferry_test_graphql2/queries/__generated__/reviews.data.gql.dart'; | ||
import 'package:ferry_test_graphql2/queries/__generated__/reviews.req.gql.dart'; | ||
import 'package:gql_exec/gql_exec.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class _TestContextEntry implements ContextEntry { | ||
final String test; | ||
_TestContextEntry({required this.test}); | ||
|
||
@override | ||
List<Object?> get fieldsForEquality => [test]; | ||
} | ||
|
||
void main() { | ||
test('passes context to links', () async { | ||
// network response | ||
final link = Link.function((request, [forward]) { | ||
final contextTest = request.context.entry<_TestContextEntry>()!.test; | ||
final data = GReviewsData((b) => b | ||
..reviews.addAll([ | ||
GReviewsData_reviews((b) => b | ||
..id = '1' | ||
..commentary = contextTest | ||
..stars = 5), | ||
])).toJson(); | ||
|
||
return Stream.value(Response( | ||
errors: [], | ||
data: data, | ||
response: data, | ||
)); | ||
}); | ||
|
||
final client = Client(link: link); | ||
|
||
final req = GReviewsReq((b) => b | ||
..vars.first = 3 | ||
..vars.offset = 0 | ||
..context = | ||
Context.fromList([_TestContextEntry(test: 'some contextual value')])); | ||
|
||
final result = await client.request(req).first; | ||
|
||
expect(result.data!.reviews!.first!.commentary, 'some contextual value'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters