File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ export default async function refetch(
62
62
for ( let query of queries . values ( ) ) {
63
63
const { document , observableQuery } = query
64
64
if ( ! observableQuery ) continue
65
+ if ( observableQuery . options . fetchPolicy === 'cache-only' ) continue
65
66
let data
66
67
const currentResult = observableQuery . currentResult ( )
67
68
if ( currentResult ) data = currentResult . data
Original file line number Diff line number Diff line change @@ -140,6 +140,52 @@ describe(`integration test`, function() {
140
140
expect ( error ) . to . exist
141
141
} )
142
142
143
+ it ( `ignores cache-only query` , async function ( ) : Promise < void > {
144
+ const query = gql `
145
+ {
146
+ orgs: Organizations {
147
+ id
148
+ name
149
+ Users {
150
+ id
151
+ username
152
+ }
153
+ }
154
+ }
155
+ `
156
+
157
+ await client . query ( { query } )
158
+
159
+ const observableQuery = client . watchQuery ( {
160
+ query,
161
+ fetchPolicy : 'cache-only' ,
162
+ } )
163
+ observableQuery . subscribe ( { } )
164
+ const {
165
+ data : { orgs } ,
166
+ } = ( observableQuery . currentResult ( ) : any )
167
+ expect ( orgs . map ( ( { id } ) => id ) ) . to . deep . equal ( [ ...Organizations . keys ( ) ] )
168
+ expect ( orgs . map ( ( { Users } ) => Users . map ( ( { id } ) => id ) ) ) . to . deep . equal ( [
169
+ [ 1 , 2 ] ,
170
+ [ 2 , 3 ] ,
171
+ ] )
172
+
173
+ Users . delete ( 2 )
174
+ for ( let org of Organizations . values ( ) ) {
175
+ org . userIds = org . userIds . filter ( id => id !== 2 )
176
+ }
177
+
178
+ await refetch ( client , 'User' , u => u . id === 2 )
179
+
180
+ const {
181
+ data : { orgs : finalOrgs } ,
182
+ } = ( observableQuery . currentResult ( ) : any )
183
+
184
+ expect (
185
+ finalOrgs . map ( ( { Users } ) => Users . map ( ( { id } ) => id ) )
186
+ ) . to . deep . equal ( [ [ 1 , 2 ] , [ 2 , 3 ] ] )
187
+ } )
188
+
143
189
it ( `handles deleted User` , async function ( ) : Promise < void > {
144
190
const query = gql `
145
191
{
You can’t perform that action at this time.
0 commit comments