|
1 | | -import { onlyCompleteData } from 'apollo-angular'; |
2 | | -import { Subject } from 'rxjs'; |
| 1 | +import { Apollo, gql, onlyCompleteData, onlyCompleteFragment, provideApollo } from 'apollo-angular'; |
| 2 | +import { map, Subject } from 'rxjs'; |
3 | 3 | import { describe, expect, test } from 'vitest'; |
4 | | -import { NetworkStatus, ObservableQuery } from '@apollo/client/core'; |
| 4 | +import { TestBed } from '@angular/core/testing'; |
| 5 | +import { InMemoryCache, NetworkStatus, type ObservableQuery } from '@apollo/client/core'; |
| 6 | +import { MockLink } from '@apollo/client/testing'; |
5 | 7 |
|
6 | 8 | interface Result { |
7 | 9 | user: { |
8 | 10 | name: string; |
9 | 11 | }; |
10 | 12 | } |
11 | 13 |
|
| 14 | +const query = gql<Result, Record<string, never>>` |
| 15 | + query User { |
| 16 | + user { |
| 17 | + name |
| 18 | + } |
| 19 | + } |
| 20 | +`; |
| 21 | + |
| 22 | +const fragment = gql<Result, Record<string, never>>` |
| 23 | + fragment UserFragment on User { |
| 24 | + user { |
| 25 | + name |
| 26 | + } |
| 27 | + } |
| 28 | +`; |
| 29 | + |
12 | 30 | describe('onlyCompleteData', () => { |
13 | 31 | let theUser: Result['user'] | null = null; |
14 | 32 | let count = 0; |
@@ -54,4 +72,41 @@ describe('onlyCompleteData', () => { |
54 | 72 |
|
55 | 73 | b.complete(); |
56 | 74 | })); |
| 75 | + |
| 76 | + test('should compile', () => { |
| 77 | + TestBed.configureTestingModule({ |
| 78 | + providers: [ |
| 79 | + provideApollo(() => { |
| 80 | + return { |
| 81 | + link: new MockLink([]), |
| 82 | + cache: new InMemoryCache(), |
| 83 | + }; |
| 84 | + }), |
| 85 | + ], |
| 86 | + }); |
| 87 | + |
| 88 | + const apollo = TestBed.inject(Apollo); |
| 89 | + |
| 90 | + apollo |
| 91 | + .watchQuery({ |
| 92 | + query: query, |
| 93 | + }) |
| 94 | + .valueChanges.pipe( |
| 95 | + onlyCompleteData(), |
| 96 | + map(result => result.data.user.name), |
| 97 | + ); |
| 98 | + |
| 99 | + apollo |
| 100 | + .watchFragment({ |
| 101 | + fragment: fragment, |
| 102 | + from: { |
| 103 | + __typename: 'User', |
| 104 | + id: 1, |
| 105 | + }, |
| 106 | + }) |
| 107 | + .pipe( |
| 108 | + onlyCompleteFragment(), |
| 109 | + map(result => result.data.user.name), |
| 110 | + ); |
| 111 | + }); |
57 | 112 | }); |
0 commit comments