Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(breaking) - Remove pollInterval option from urql (#1374)

* Remove `pollInterval` OperationContext option from @urql/core

* Remove pollInterval from react-urql

* Remove `pollInterval` option from @urql/vue

* Remove polling tests from @urql/vue

* Remove pollInterval from docs

* Add fat breaking warning to changesets

authored by

Phil Pluckthun and committed by
GitHub
97689ff9 2b4557da

+19 -103
+5
.changeset/gorgeous-squids-exercise.md
··· 1 + --- 2 + '@urql/core': major 3 + --- 4 + 5 + **Breaking**: Remove `pollInterval` feature from `OperationContext`. Instead consider using a source that uses `Wonka.interval` and `Wonka.switchMap` over `client.query()`'s source.
+5
.changeset/great-rice-lick.md
··· 1 + --- 2 + '@urql/vue': minor 3 + --- 4 + 5 + **Breaking**: Remove `pollInterval` option from `useQuery`. Please consider adding an interval manually calling `executeQuery()`.
+6
.changeset/twelve-camels-sit.md
··· 1 + --- 2 + 'urql': major 3 + '@urql/preact': major 4 + --- 5 + 6 + **Breaking**: Remove `pollInterval` option from `useQuery`. Instead please consider using `useEffect` calling `executeQuery` on an interval.
-6
docs/api/core.md
··· 46 46 instead.](#clientquery) 47 47 - [See `createRequest` for a utility that creates `GraphQLRequest` objects.](#createrequest) 48 48 49 - A feature that is specific to `client.executeQuery` and isn't supported by 50 - `client.executeSubscription` and `client.executeMutation` is polling. You may optionally pass a 51 - `pollInterval` option on the `OperationContext` object, which will instruct the query to reexecute 52 - repeatedly in the interval you pass. 53 - 54 49 ### client.executeSubscription 55 50 56 51 This is functionally the same as `client.executeQuery`, but creates operations for subscriptions ··· 211 206 | `fetch` | `typeof fetch` | An alternative implementation of `fetch` that will be used by the `fetchExchange` instead of `window.fetch` | 212 207 | `requestPolicy` | `RequestPolicy` | An optional [request policy](/basics/querying-data#request-policy) that should be used specifying the cache strategy. | 213 208 | `url` | `string` | The GraphQL endpoint | 214 - | `pollInterval` | `?number` | Every `pollInterval` milliseconds the query will be refetched. | 215 209 | `meta` | `?OperationDebugMeta` | Metadata that is only available in development for devtools. | 216 210 | `suspense` | `?boolean` | Whether suspense is enabled. | 217 211 | `preferGetMethod` | `?boolean` | Instructs the `fetchExchange` to use HTTP GET for queries. |
-1
docs/api/urql.md
··· 15 15 | `variables` | `?object` | The variables to be used with the GraphQL request. | 16 16 | `requestPolicy` | `?RequestPolicy` | An optional [request policy](./core.md#requestpolicy) that should be used specifying the cache strategy. | 17 17 | `pause` | `?boolean` | A boolean flag instructing [execution to be paused](../basics/queries.md#pausing-usequery). | 18 - | `pollInterval` | `?number` | Every `pollInterval` milliseconds the query will be reexecuted. | 19 18 | `context` | `?object` | Holds the contextual information for the query. | 20 19 21 20 This hook returns a tuple of the shape `[result, executeQuery]`.
-1
docs/api/vue.md
··· 15 15 | `variables` | `?object` | The variables to be used with the GraphQL request. | 16 16 | `requestPolicy` | `?RequestPolicy` | An optional [request policy](./core.md#requestpolicy) that should be used specifying the cache strategy. | 17 17 | `pause` | `?boolean` | A boolean flag instructing [execution to be paused](../basics/vue.md#pausing-usequery). | 18 - | `pollInterval` | `?number` | Every `pollInterval` milliseconds the query will be reexecuted. | 19 18 | `context` | `?object` | Holds the contextual information for the query. | 20 19 21 20 Each of these inputs may also be [reactive](https://v3.vuejs.org/api/refs-api.html) (e.g. a `ref`)
-18
packages/core/src/client.test.ts
··· 220 220 221 221 expect(receivedOps[0]).toHaveProperty('context.url', url); 222 222 }); 223 - 224 - it('polls when pollInterval is specified', () => { 225 - jest.useFakeTimers(); 226 - const { unsubscribe } = pipe( 227 - client.executeQuery(query, { pollInterval: 100 }), 228 - subscribe(x => x) 229 - ); 230 - 231 - expect(receivedOps.length).toEqual(1); 232 - jest.advanceTimersByTime(200); 233 - expect(receivedOps.length).toEqual(5); 234 - expect(receivedOps[0].kind).toEqual('query'); 235 - expect(receivedOps[1].kind).toEqual('teardown'); 236 - expect(receivedOps[2].kind).toEqual('query'); 237 - expect(receivedOps[3].kind).toEqual('teardown'); 238 - expect(receivedOps[4].kind).toEqual('query'); 239 - unsubscribe(); 240 - }); 241 223 }); 242 224 243 225 describe('executeMutation', () => {
-11
packages/core/src/client.ts
··· 10 10 Source, 11 11 take, 12 12 takeUntil, 13 - merge, 14 - interval, 15 - fromValue, 16 - switchMap, 17 13 publish, 18 14 subscribe, 19 15 map, ··· 268 264 this.onOperationEnd(operation); 269 265 }) 270 266 ); 271 - 272 - if (operation.kind === 'query' && operation.context.pollInterval) { 273 - return pipe( 274 - merge([fromValue(0), interval(operation.context.pollInterval)]), 275 - switchMap(() => result$) 276 - ); 277 - } 278 267 279 268 return result$; 280 269 }
-1
packages/core/src/types.ts
··· 47 47 fetchOptions?: RequestInit | (() => RequestInit); 48 48 requestPolicy: RequestPolicy; 49 49 url: string; 50 - pollInterval?: number; 51 50 meta?: OperationDebugMeta; 52 51 suspense?: boolean; 53 52 preferGetMethod?: boolean;
+1 -3
packages/preact-urql/src/hooks/useQuery.ts
··· 32 32 query: string | DocumentNode | TypedDocumentNode<Data, Variables>; 33 33 variables?: Variables; 34 34 requestPolicy?: RequestPolicy; 35 - pollInterval?: number; 36 35 context?: Partial<OperationContext>; 37 36 pause?: boolean; 38 37 } ··· 112 111 if (!source) { 113 112 source = client.executeQuery(request, { 114 113 requestPolicy: args.requestPolicy, 115 - pollInterval: args.pollInterval, 116 114 ...args.context, 117 115 ...opts, 118 116 }); ··· 128 126 129 127 return source; 130 128 }, 131 - [client, request, args.requestPolicy, args.pollInterval, args.context] 129 + [client, request, args.requestPolicy, args.context] 132 130 ); 133 131 134 132 const query$ = useMemo(() => {
+2 -21
packages/react-urql/src/hooks/useQuery.ts
··· 21 21 query: string | DocumentNode | TypedDocumentNode<Data, Variables>; 22 22 variables?: Variables; 23 23 requestPolicy?: RequestPolicy; 24 - pollInterval?: number; 25 24 context?: Partial<OperationContext>; 26 25 pause?: boolean; 27 26 } ··· 56 55 57 56 const source = client.executeQuery(request, { 58 57 requestPolicy: args.requestPolicy, 59 - pollInterval: args.pollInterval, 60 58 ...args.context, 61 59 }); 62 60 ··· 68 66 }) 69 67 ) 70 68 : source; 71 - }, [ 72 - client, 73 - request, 74 - suspense, 75 - args.pause, 76 - args.requestPolicy, 77 - args.pollInterval, 78 - args.context, 79 - ]); 69 + }, [client, request, suspense, args.pause, args.requestPolicy, args.context]); 80 70 81 71 const getSnapshot = useCallback( 82 72 ( ··· 121 111 client, 122 112 request, 123 113 args.requestPolicy, 124 - args.pollInterval, 125 114 args.context, 126 115 args.pause, 127 116 ] as const; ··· 187 176 (opts?: Partial<OperationContext>) => { 188 177 const context = { 189 178 requestPolicy: args.requestPolicy, 190 - pollInterval: args.pollInterval, 191 179 ...args.context, 192 180 ...opts, 193 181 }; ··· 203 191 return state[1] !== nextResult ? [source, nextResult, state[2]] : state; 204 192 }); 205 193 }, 206 - [ 207 - client, 208 - request, 209 - getSnapshot, 210 - args.requestPolicy, 211 - args.pollInterval, 212 - args.context, 213 - ] 194 + [client, request, getSnapshot, args.requestPolicy, args.context] 214 195 ); 215 196 216 197 return [currentResult, executeQuery];
-38
packages/vue-urql/src/useQuery.test.ts
··· 49 49 context: undefined, 50 50 }, 51 51 { 52 - pollInterval: undefined, 53 52 requestPolicy: undefined, 54 53 } 55 54 ); ··· 130 129 131 130 expect(query.fetching).toBe(false); 132 131 expect(query.data).toEqual({ test: true }); 133 - }); 134 - 135 - it('updates when polling', async () => { 136 - const subject = makeSubject<any>(); 137 - const executeQuery = jest 138 - .spyOn(client, 'executeQuery') 139 - .mockImplementation(() => subject.source); 140 - 141 - const _query = useQuery({ 142 - query: `{ test }`, 143 - pollInterval: 500, 144 - requestPolicy: 'cache-first', 145 - }); 146 - const query = reactive(_query); 147 - 148 - expect(executeQuery).toHaveBeenCalledWith( 149 - { 150 - key: expect.any(Number), 151 - query: expect.any(Object), 152 - variables: {}, 153 - context: undefined, 154 - }, 155 - { 156 - pollInterval: 500, 157 - requestPolicy: 'cache-first', 158 - } 159 - ); 160 - 161 - expect(query.fetching).toBe(true); 162 - 163 - subject.next({ data: { test: true } }); 164 - 165 - expect(query.fetching).toBe(false); 166 - expect(query.data).toEqual({ test: true }); 167 - 168 - subject.next({ data: { test: false } }); 169 - expect(query.data).toEqual({ test: false }); 170 132 }); 171 133 });
-3
packages/vue-urql/src/useQuery.ts
··· 38 38 query: MaybeRef<TypedDocumentNode<T, V> | DocumentNode | string>; 39 39 variables?: MaybeRef<V>; 40 40 requestPolicy?: MaybeRef<RequestPolicy>; 41 - pollInterval?: MaybeRef<number>; 42 41 context?: MaybeRef<Partial<OperationContext>>; 43 42 pause?: MaybeRef<boolean>; 44 43 } ··· 132 131 next.value( 133 132 client.executeQuery<T, V>(request.value, { 134 133 requestPolicy: args.requestPolicy, 135 - pollInterval: args.pollInterval, 136 134 ...args.context, 137 135 ...opts, 138 136 }) ··· 199 197 !isPaused.value 200 198 ? client.executeQuery<T, V>(request.value, { 201 199 requestPolicy: args.requestPolicy, 202 - pollInterval: args.pollInterval, 203 200 ...args.context, 204 201 }) 205 202 : undefined