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.

(core) - Add built-in gql tag function (#1187)

* Add built-in gql function

* Add inner document source to DocumentNodes from gql

* Update tests to use new gql helper

* Protect against invalid inputs in gql

* Fix up execute tests

* Fix linting issues in gql.ts

* Add basic tests for gql tag

* Shave some bytes off of cacheExchange

* Simplify composeExchanges helper

* Replace all usages of graphql-tag

* Update entries in docs

* Add changeset

* Revert changes / Update snapshot

* Fix linting issues in populate and core

* Add core / gql section to Queries page

authored by

Phil Pluckthun and committed by
GitHub
64668b3a 564ed1b7

+880 -211
+9
.changeset/fair-flies-grab.md
··· 1 + --- 2 + '@urql/core': minor 3 + '@urql/preact': patch 4 + 'urql': patch 5 + '@urql/svelte': patch 6 + '@urql/vue': patch 7 + --- 8 + 9 + Add a built-in `gql` tag function helper to `@urql/core`. This behaves similarly to `graphql-tag` but only warns about _locally_ duplicated fragment names rather than globally. It also primes `@urql/core`'s key cache with the parsed `DocumentNode`.
+30
docs/api/core.md
··· 353 353 354 354 ## Utilities 355 355 356 + ### gql 357 + 358 + This is a `gql` tagged template literal function, similar to the one that's also commonly known from 359 + `graphql-tag`. It can be used to write GraphQL documents in a tagged template literal and returns a 360 + parsed `DocumentNode` that's primed against the `createRequest`'s cache for `key`s. 361 + 362 + ```js 363 + import { gql } from '@urql/core'; 364 + 365 + const SharedFragment = gql` 366 + fragment UserFrag on User { 367 + id 368 + name 369 + } 370 + `; 371 + 372 + gql` 373 + query { 374 + user 375 + ...UserFrag 376 + } 377 + 378 + ${SharedFragment} 379 + `; 380 + ``` 381 + 382 + Unlike `graphql-tag`, this function outputs a warning in development when names of fragments in the 383 + document are duplicated. It does not output warnings when fragment names were duplicated globally 384 + however. 385 + 356 386 ### stringifyVariables 357 387 358 388 This function is a variation of `JSON.stringify` that sorts any object's keys that is being
+3 -3
docs/api/graphcache.md
··· 284 284 data. If any data is uncached and missing it'll return `null`. 285 285 286 286 ```js 287 - import gql from 'graphql-tag'; 287 + import { gql } from '@urql/core'; 288 288 289 289 cache.readFragment( 290 290 gql` ··· 303 303 If any fields on the fragment require variables, you can pass them as the third argument like so: 304 304 305 305 ```js 306 - import gql from 'graphql-tag'; 306 + import { gql } from '@urql/core'; 307 307 308 308 cache.readFragment( 309 309 gql` ··· 355 355 an entity key from the given data, but also the fields that will be written: 356 356 357 357 ```js 358 - import gql from 'graphql-tag'; 358 + import { gql } from '@urql/core'; 359 359 360 360 cache.writeFragment( 361 361 gql`
+84
docs/basics/queries.md
··· 815 815 it.](../api/vue.md#usequery) 816 816 817 817 [On the next page we'll learn about "Mutations" rather than Queries.](./mutations.md#vue) 818 + 819 + ## Core 820 + 821 + All framework bindings — meaning `urql`, `@urql/preact`, `@urql/svelte`, and `@urql/vue` — reexport 822 + all exports of our `@urql/core` core library. This package contains the 823 + [`Client`](../api/core.md#client), built-in exchanges, and other utilities that are shared between 824 + all bindings. 825 + 826 + ### gql 827 + 828 + A notable utility function is the `gql` tagged template literal function, which is a drop-in 829 + replacement for `graphql-tag`, if you're coming from other GraphQL clients. 830 + 831 + Wherever `urql` accepts a query document, you may either pass a string or a `DocumentNode`. `gql` is 832 + a utility that allows a `DocumentNode` to be created directly, and others to be interpolated into 833 + it, which is useful for fragments for instance. This function will often also mark GraphQL documents 834 + for syntax highlighting in most code editors. 835 + 836 + In most examples we may have passed a string to define a query document, like so: 837 + 838 + ```js 839 + const TodosQuery = ` 840 + query { 841 + todos { 842 + id 843 + title 844 + } 845 + } 846 + `; 847 + ``` 848 + 849 + We may also use the `gql` tag function to create a `DocumentNode` directly: 850 + 851 + ```js 852 + import { gql } from '@urql/core'; 853 + 854 + const TodosQuery = gql` 855 + query { 856 + todos { 857 + id 858 + title 859 + } 860 + } 861 + `; 862 + ``` 863 + 864 + Since all framework bindings also re-export `@urql/core`, we may also import `gql` from `'urql'`, 865 + `'@urql/svelte'` and other bindings directly. 866 + 867 + We can also start interpolating other documents into the tag function. This is useful to compose 868 + fragment documents into a larger query, since it's common to define fragments across components of 869 + an app to spread out data dependencies. If we accidentally use a duplicate fragment name in a 870 + document, `gql` will log a warning, since GraphQL APIs won't accept duplicate names. 871 + 872 + ```js 873 + import { gql } from '@urql/core'; 874 + 875 + const TodoFragment = gql` 876 + fragment SmallTodo on Todo { 877 + id 878 + title 879 + } 880 + `; 881 + 882 + const TodosQuery = gql` 883 + query { 884 + todos { 885 + ...TodoFragment 886 + } 887 + } 888 + 889 + ${TodoFragment} 890 + `; 891 + ``` 892 + 893 + ### Reading on 894 + 895 + There are some more utilities that `@urql/core` exports. [All of them are listed in the API docs for 896 + it.](../api/core.md) 897 + 898 + [Read more about the `@urql/core` library on the "Core Package" 899 + page.](https://formidable.com/open-source/urql/docs/concepts/core-package/) 900 + 901 +
+2 -2
docs/graphcache/computed-queries.md
··· 143 143 accepts a `fragment` and an `id`. This looks like the following. 144 144 145 145 ```js 146 - import gql from 'graphql-tag'; 146 + import { gql } from '@urql/core'; 147 147 148 148 const data = cache.readFragment( 149 149 gql` ··· 157 157 ``` 158 158 159 159 > **Note:** In the above example, we've used 160 - > [graphql-tag](https://github.com/apollographql/graphql-tag) because `writeFragment` only accepts 160 + > [the `gql` tag function](../api/core.md#gql) because `readFragment` only accepts 161 161 > GraphQL `DocumentNode`s as inputs, and not strings. 162 162 163 163 This way we'll get the Todo with id 1 and the relevant data we are asking for in the
+3 -3
docs/graphcache/custom-updates.md
··· 104 104 contain `id` or another field if the type has a custom `keys` configuration. 105 105 106 106 ```js 107 - import gql from 'graphql-tag'; 107 + import { gql } from '@urql/core'; 108 108 109 109 cache.writeFragment( 110 110 gql` ··· 121 121 ``` 122 122 123 123 > **Note:** In the above example, we've used 124 - > [graphql-tag](https://github.com/apollographql/graphql-tag) because `writeFragment` only accepts 124 + > [the `gql` tag function](../api/core.md#gql) because `writeFragment` only accepts 125 125 > GraphQL `DocumentNode`s as inputs, and not strings. 126 126 127 127 This can be useful for instance if we have a mutation that doesn't return the type that the GraphQL ··· 130 130 manually: 131 131 132 132 ```js 133 - import gql from 'graphql-tag'; 133 + import { gql } from '@urql/core'; 134 134 135 135 const cache = cacheExchange({ 136 136 updates: {
+1 -2
exchanges/auth/package.json
··· 58 58 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 59 59 }, 60 60 "devDependencies": { 61 - "graphql": "^15.4.0", 62 - "graphql-tag": "^2.10.1" 61 + "graphql": "^15.4.0" 63 62 }, 64 63 "publishConfig": { 65 64 "access": "public"
+1 -2
exchanges/execute/package.json
··· 58 58 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 59 59 }, 60 60 "devDependencies": { 61 - "graphql": "^15.4.0", 62 - "graphql-tag": "^2.10.1" 61 + "graphql": "^15.4.0" 63 62 }, 64 63 "publishConfig": { 65 64 "access": "public"
+15 -7
exchanges/execute/src/execute.test.ts
··· 1 - jest.mock('graphql'); 1 + jest.mock('graphql', () => { 2 + const graphql = jest.requireActual('graphql'); 3 + 4 + return { 5 + __esModule: true, 6 + ...graphql, 7 + print: jest.fn(a => a as any), 8 + execute: jest.fn(() => ({ key: 'value' })), 9 + }; 10 + }); 2 11 3 12 import { fetchExchange } from 'urql'; 4 13 import { executeExchange } from './execute'; ··· 31 40 const expectedOperationName = getOperationName(queryOperation.query); 32 41 33 42 const fetchMock = (global as any).fetch as jest.Mock; 34 - afterEach(() => { 35 - fetchMock.mockClear(); 36 - }); 37 - 38 43 const mockHttpResponseData = { key: 'value' }; 39 - 40 - beforeEach(jest.clearAllMocks); 41 44 42 45 beforeEach(() => { 46 + jest.clearAllMocks(); 43 47 mocked(print).mockImplementation(a => a as any); 44 48 mocked(execute).mockResolvedValue({ data: mockHttpResponseData }); 49 + }); 50 + 51 + afterEach(() => { 52 + fetchMock.mockClear(); 45 53 }); 46 54 47 55 describe('on operation', () => {
+1 -2
exchanges/graphcache/package.json
··· 72 72 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 73 73 }, 74 74 "devDependencies": { 75 - "graphql": "^15.4.0", 76 - "graphql-tag": "^2.10.1" 75 + "graphql": "^15.4.0" 77 76 }, 78 77 "publishConfig": { 79 78 "access": "public"
+1 -1
exchanges/graphcache/src/ast/traversal.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { getSelectionSet } from './node'; 3 3 4 4 import { getMainOperation, shouldInclude } from './traversal';
+1 -1
exchanges/graphcache/src/ast/variables.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { getMainOperation } from './traversal'; 3 3 import { normalizeVariables, filterVariables } from './variables'; 4 4
+1 -2
exchanges/graphcache/src/cacheExchange.test.ts
··· 1 - import gql from 'graphql-tag'; 2 - 3 1 import { 2 + gql, 4 3 createClient, 5 4 ExchangeIO, 6 5 Operation,
+1 -1
exchanges/graphcache/src/extras/relayPagination.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { query, write } from '../operations'; 3 3 import { Store } from '../store'; 4 4 import { relayPagination } from './relayPagination';
+1 -1
exchanges/graphcache/src/extras/simplePagination.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { query, write } from '../operations'; 3 3 import { Store } from '../store'; 4 4 import { simplePagination } from './simplePagination';
+1 -1
exchanges/graphcache/src/offlineExchange.test.ts
··· 1 1 import { 2 + gql, 2 3 createClient, 3 4 ExchangeIO, 4 5 Operation, ··· 6 7 formatDocument, 7 8 } from '@urql/core'; 8 9 9 - import gql from 'graphql-tag'; 10 10 import { pipe, map, makeSubject, tap, publish } from 'wonka'; 11 11 import { offlineExchange } from './offlineExchange'; 12 12
+1 -1
exchanges/graphcache/src/operations/query.test.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-var-requires */ 2 2 3 - import gql from 'graphql-tag'; 3 + import { gql } from '@urql/core'; 4 4 import { minifyIntrospectionQuery } from '@urql/introspection'; 5 5 6 6 import { Store } from '../store';
+1 -1
exchanges/graphcache/src/operations/write.test.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-var-requires */ 2 2 3 - import gql from 'graphql-tag'; 3 + import { gql } from '@urql/core'; 4 4 import { minifyIntrospectionQuery } from '@urql/introspection'; 5 5 6 6 import { write } from './write';
+1 -2
exchanges/graphcache/src/store/store.test.ts
··· 1 1 /* eslint-disable @typescript-eslint/no-var-requires */ 2 2 3 - import gql from 'graphql-tag'; 4 3 import { minifyIntrospectionQuery } from '@urql/introspection'; 5 - import { maskTypename } from '@urql/core'; 4 + import { gql, maskTypename } from '@urql/core'; 6 5 import { mocked } from 'ts-jest/utils'; 7 6 8 7 import { Data, StorageAdapter } from '../types';
+1 -1
exchanges/graphcache/src/test-utils/examples-1.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { query, write, writeOptimistic } from '../operations'; 3 3 import * as InMemoryData from '../store/data'; 4 4 import { Store } from '../store';
+1 -1
exchanges/graphcache/src/test-utils/examples-2.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { query, write } from '../operations'; 3 3 import { Store } from '../store'; 4 4
+1 -1
exchanges/graphcache/src/test-utils/examples-3.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { query, write } from '../operations'; 3 3 import { Store } from '../store'; 4 4
+1 -1
exchanges/graphcache/src/test-utils/suite.test.ts
··· 1 1 import { DocumentNode } from 'graphql'; 2 - import gql from 'graphql-tag'; 2 + import { gql } from '@urql/core'; 3 3 import { query, write } from '../operations'; 4 4 import { Store } from '../store'; 5 5
+1 -2
exchanges/multipart-fetch/package.json
··· 57 57 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 58 58 }, 59 59 "devDependencies": { 60 - "graphql": "^15.4.0", 61 - "graphql-tag": "^2.10.1" 60 + "graphql": "^15.4.0" 62 61 }, 63 62 "publishConfig": { 64 63 "access": "public"
+179
exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap
··· 17 17 "kind": "query", 18 18 "operationName": "query", 19 19 "query": Object { 20 + "__key": 3044551916, 20 21 "definitions": Array [ 21 22 Object { 22 23 "directives": Array [], 23 24 "kind": "OperationDefinition", 25 + "loc": undefined, 24 26 "name": Object { 25 27 "kind": "Name", 28 + "loc": undefined, 26 29 "value": "getUser", 27 30 }, 28 31 "operation": "query", 29 32 "selectionSet": Object { 30 33 "kind": "SelectionSet", 34 + "loc": undefined, 31 35 "selections": Array [ 32 36 Object { 33 37 "alias": undefined, 34 38 "arguments": Array [ 35 39 Object { 36 40 "kind": "Argument", 41 + "loc": undefined, 37 42 "name": Object { 38 43 "kind": "Name", 44 + "loc": undefined, 39 45 "value": "name", 40 46 }, 41 47 "value": Object { 42 48 "kind": "Variable", 49 + "loc": undefined, 43 50 "name": Object { 44 51 "kind": "Name", 52 + "loc": undefined, 45 53 "value": "name", 46 54 }, 47 55 }, ··· 49 57 ], 50 58 "directives": Array [], 51 59 "kind": "Field", 60 + "loc": undefined, 52 61 "name": Object { 53 62 "kind": "Name", 63 + "loc": undefined, 54 64 "value": "user", 55 65 }, 56 66 "selectionSet": Object { 57 67 "kind": "SelectionSet", 68 + "loc": undefined, 58 69 "selections": Array [ 59 70 Object { 60 71 "alias": undefined, 61 72 "arguments": Array [], 62 73 "directives": Array [], 63 74 "kind": "Field", 75 + "loc": undefined, 64 76 "name": Object { 65 77 "kind": "Name", 78 + "loc": undefined, 66 79 "value": "id", 67 80 }, 68 81 "selectionSet": undefined, ··· 72 85 "arguments": Array [], 73 86 "directives": Array [], 74 87 "kind": "Field", 88 + "loc": undefined, 75 89 "name": Object { 76 90 "kind": "Name", 91 + "loc": undefined, 77 92 "value": "firstName", 78 93 }, 79 94 "selectionSet": undefined, ··· 83 98 "arguments": Array [], 84 99 "directives": Array [], 85 100 "kind": "Field", 101 + "loc": undefined, 86 102 "name": Object { 87 103 "kind": "Name", 104 + "loc": undefined, 88 105 "value": "lastName", 89 106 }, 90 107 "selectionSet": undefined, ··· 99 116 "defaultValue": undefined, 100 117 "directives": Array [], 101 118 "kind": "VariableDefinition", 119 + "loc": undefined, 102 120 "type": Object { 103 121 "kind": "NamedType", 122 + "loc": undefined, 104 123 "name": Object { 105 124 "kind": "Name", 125 + "loc": undefined, 106 126 "value": "String", 107 127 }, 108 128 }, 109 129 "variable": Object { 110 130 "kind": "Variable", 131 + "loc": undefined, 111 132 "name": Object { 112 133 "kind": "Name", 134 + "loc": undefined, 113 135 "value": "name", 114 136 }, 115 137 }, ··· 120 142 "kind": "Document", 121 143 "loc": Object { 122 144 "end": 124, 145 + "source": Source { 146 + "body": " 147 + query getUser($name: String) { 148 + user(name: $name) { 149 + id 150 + firstName 151 + lastName 152 + } 153 + } 154 + ", 155 + "locationOffset": Object { 156 + "column": 1, 157 + "line": 1, 158 + }, 159 + "name": "gql", 160 + }, 123 161 "start": 0, 124 162 }, 125 163 }, ··· 157 195 "kind": "query", 158 196 "operationName": "query", 159 197 "query": Object { 198 + "__key": 3044551916, 160 199 "definitions": Array [ 161 200 Object { 162 201 "directives": Array [], 163 202 "kind": "OperationDefinition", 203 + "loc": undefined, 164 204 "name": Object { 165 205 "kind": "Name", 206 + "loc": undefined, 166 207 "value": "getUser", 167 208 }, 168 209 "operation": "query", 169 210 "selectionSet": Object { 170 211 "kind": "SelectionSet", 212 + "loc": undefined, 171 213 "selections": Array [ 172 214 Object { 173 215 "alias": undefined, 174 216 "arguments": Array [ 175 217 Object { 176 218 "kind": "Argument", 219 + "loc": undefined, 177 220 "name": Object { 178 221 "kind": "Name", 222 + "loc": undefined, 179 223 "value": "name", 180 224 }, 181 225 "value": Object { 182 226 "kind": "Variable", 227 + "loc": undefined, 183 228 "name": Object { 184 229 "kind": "Name", 230 + "loc": undefined, 185 231 "value": "name", 186 232 }, 187 233 }, ··· 189 235 ], 190 236 "directives": Array [], 191 237 "kind": "Field", 238 + "loc": undefined, 192 239 "name": Object { 193 240 "kind": "Name", 241 + "loc": undefined, 194 242 "value": "user", 195 243 }, 196 244 "selectionSet": Object { 197 245 "kind": "SelectionSet", 246 + "loc": undefined, 198 247 "selections": Array [ 199 248 Object { 200 249 "alias": undefined, 201 250 "arguments": Array [], 202 251 "directives": Array [], 203 252 "kind": "Field", 253 + "loc": undefined, 204 254 "name": Object { 205 255 "kind": "Name", 256 + "loc": undefined, 206 257 "value": "id", 207 258 }, 208 259 "selectionSet": undefined, ··· 212 263 "arguments": Array [], 213 264 "directives": Array [], 214 265 "kind": "Field", 266 + "loc": undefined, 215 267 "name": Object { 216 268 "kind": "Name", 269 + "loc": undefined, 217 270 "value": "firstName", 218 271 }, 219 272 "selectionSet": undefined, ··· 223 276 "arguments": Array [], 224 277 "directives": Array [], 225 278 "kind": "Field", 279 + "loc": undefined, 226 280 "name": Object { 227 281 "kind": "Name", 282 + "loc": undefined, 228 283 "value": "lastName", 229 284 }, 230 285 "selectionSet": undefined, ··· 239 294 "defaultValue": undefined, 240 295 "directives": Array [], 241 296 "kind": "VariableDefinition", 297 + "loc": undefined, 242 298 "type": Object { 243 299 "kind": "NamedType", 300 + "loc": undefined, 244 301 "name": Object { 245 302 "kind": "Name", 303 + "loc": undefined, 246 304 "value": "String", 247 305 }, 248 306 }, 249 307 "variable": Object { 250 308 "kind": "Variable", 309 + "loc": undefined, 251 310 "name": Object { 252 311 "kind": "Name", 312 + "loc": undefined, 253 313 "value": "name", 254 314 }, 255 315 }, ··· 260 320 "kind": "Document", 261 321 "loc": Object { 262 322 "end": 124, 323 + "source": Source { 324 + "body": " 325 + query getUser($name: String) { 326 + user(name: $name) { 327 + id 328 + firstName 329 + lastName 330 + } 331 + } 332 + ", 333 + "locationOffset": Object { 334 + "column": 1, 335 + "line": 1, 336 + }, 337 + "name": "gql", 338 + }, 263 339 "start": 0, 264 340 }, 265 341 }, ··· 299 375 "kind": "query", 300 376 "operationName": "query", 301 377 "query": Object { 378 + "__key": 3044551916, 302 379 "definitions": Array [ 303 380 Object { 304 381 "directives": Array [], 305 382 "kind": "OperationDefinition", 383 + "loc": undefined, 306 384 "name": Object { 307 385 "kind": "Name", 386 + "loc": undefined, 308 387 "value": "getUser", 309 388 }, 310 389 "operation": "query", 311 390 "selectionSet": Object { 312 391 "kind": "SelectionSet", 392 + "loc": undefined, 313 393 "selections": Array [ 314 394 Object { 315 395 "alias": undefined, 316 396 "arguments": Array [ 317 397 Object { 318 398 "kind": "Argument", 399 + "loc": undefined, 319 400 "name": Object { 320 401 "kind": "Name", 402 + "loc": undefined, 321 403 "value": "name", 322 404 }, 323 405 "value": Object { 324 406 "kind": "Variable", 407 + "loc": undefined, 325 408 "name": Object { 326 409 "kind": "Name", 410 + "loc": undefined, 327 411 "value": "name", 328 412 }, 329 413 }, ··· 331 415 ], 332 416 "directives": Array [], 333 417 "kind": "Field", 418 + "loc": undefined, 334 419 "name": Object { 335 420 "kind": "Name", 421 + "loc": undefined, 336 422 "value": "user", 337 423 }, 338 424 "selectionSet": Object { 339 425 "kind": "SelectionSet", 426 + "loc": undefined, 340 427 "selections": Array [ 341 428 Object { 342 429 "alias": undefined, 343 430 "arguments": Array [], 344 431 "directives": Array [], 345 432 "kind": "Field", 433 + "loc": undefined, 346 434 "name": Object { 347 435 "kind": "Name", 436 + "loc": undefined, 348 437 "value": "id", 349 438 }, 350 439 "selectionSet": undefined, ··· 354 443 "arguments": Array [], 355 444 "directives": Array [], 356 445 "kind": "Field", 446 + "loc": undefined, 357 447 "name": Object { 358 448 "kind": "Name", 449 + "loc": undefined, 359 450 "value": "firstName", 360 451 }, 361 452 "selectionSet": undefined, ··· 365 456 "arguments": Array [], 366 457 "directives": Array [], 367 458 "kind": "Field", 459 + "loc": undefined, 368 460 "name": Object { 369 461 "kind": "Name", 462 + "loc": undefined, 370 463 "value": "lastName", 371 464 }, 372 465 "selectionSet": undefined, ··· 381 474 "defaultValue": undefined, 382 475 "directives": Array [], 383 476 "kind": "VariableDefinition", 477 + "loc": undefined, 384 478 "type": Object { 385 479 "kind": "NamedType", 480 + "loc": undefined, 386 481 "name": Object { 387 482 "kind": "Name", 483 + "loc": undefined, 388 484 "value": "String", 389 485 }, 390 486 }, 391 487 "variable": Object { 392 488 "kind": "Variable", 489 + "loc": undefined, 393 490 "name": Object { 394 491 "kind": "Name", 492 + "loc": undefined, 395 493 "value": "name", 396 494 }, 397 495 }, ··· 402 500 "kind": "Document", 403 501 "loc": Object { 404 502 "end": 124, 503 + "source": Source { 504 + "body": " 505 + query getUser($name: String) { 506 + user(name: $name) { 507 + id 508 + firstName 509 + lastName 510 + } 511 + } 512 + ", 513 + "locationOffset": Object { 514 + "column": 1, 515 + "line": 1, 516 + }, 517 + "name": "gql", 518 + }, 405 519 "start": 0, 406 520 }, 407 521 }, ··· 443 557 "kind": "mutation", 444 558 "operationName": "mutation", 445 559 "query": Object { 560 + "__key": 3781860981, 446 561 "definitions": Array [ 447 562 Object { 448 563 "directives": Array [], 449 564 "kind": "OperationDefinition", 565 + "loc": undefined, 450 566 "name": Object { 451 567 "kind": "Name", 568 + "loc": undefined, 452 569 "value": "uploadProfilePicture", 453 570 }, 454 571 "operation": "mutation", 455 572 "selectionSet": Object { 456 573 "kind": "SelectionSet", 574 + "loc": undefined, 457 575 "selections": Array [ 458 576 Object { 459 577 "alias": undefined, 460 578 "arguments": Array [ 461 579 Object { 462 580 "kind": "Argument", 581 + "loc": undefined, 463 582 "name": Object { 464 583 "kind": "Name", 584 + "loc": undefined, 465 585 "value": "picture", 466 586 }, 467 587 "value": Object { 468 588 "kind": "Variable", 589 + "loc": undefined, 469 590 "name": Object { 470 591 "kind": "Name", 592 + "loc": undefined, 471 593 "value": "picture", 472 594 }, 473 595 }, ··· 475 597 ], 476 598 "directives": Array [], 477 599 "kind": "Field", 600 + "loc": undefined, 478 601 "name": Object { 479 602 "kind": "Name", 603 + "loc": undefined, 480 604 "value": "uploadProfilePicture", 481 605 }, 482 606 "selectionSet": Object { 483 607 "kind": "SelectionSet", 608 + "loc": undefined, 484 609 "selections": Array [ 485 610 Object { 486 611 "alias": undefined, 487 612 "arguments": Array [], 488 613 "directives": Array [], 489 614 "kind": "Field", 615 + "loc": undefined, 490 616 "name": Object { 491 617 "kind": "Name", 618 + "loc": undefined, 492 619 "value": "location", 493 620 }, 494 621 "selectionSet": undefined, ··· 503 630 "defaultValue": undefined, 504 631 "directives": Array [], 505 632 "kind": "VariableDefinition", 633 + "loc": undefined, 506 634 "type": Object { 507 635 "kind": "NamedType", 636 + "loc": undefined, 508 637 "name": Object { 509 638 "kind": "Name", 639 + "loc": undefined, 510 640 "value": "File", 511 641 }, 512 642 }, 513 643 "variable": Object { 514 644 "kind": "Variable", 645 + "loc": undefined, 515 646 "name": Object { 516 647 "kind": "Name", 648 + "loc": undefined, 517 649 "value": "picture", 518 650 }, 519 651 }, ··· 524 656 "kind": "Document", 525 657 "loc": Object { 526 658 "end": 134, 659 + "source": Source { 660 + "body": " 661 + mutation uploadProfilePicture($picture: File) { 662 + uploadProfilePicture(picture: $picture) { 663 + location 664 + } 665 + } 666 + ", 667 + "locationOffset": Object { 668 + "column": 1, 669 + "line": 1, 670 + }, 671 + "name": "gql", 672 + }, 527 673 "start": 0, 528 674 }, 529 675 }, ··· 567 713 "kind": "mutation", 568 714 "operationName": "mutation", 569 715 "query": Object { 716 + "__key": 1193185401, 570 717 "definitions": Array [ 571 718 Object { 572 719 "directives": Array [], 573 720 "kind": "OperationDefinition", 721 + "loc": undefined, 574 722 "name": Object { 575 723 "kind": "Name", 724 + "loc": undefined, 576 725 "value": "uploadProfilePictures", 577 726 }, 578 727 "operation": "mutation", 579 728 "selectionSet": Object { 580 729 "kind": "SelectionSet", 730 + "loc": undefined, 581 731 "selections": Array [ 582 732 Object { 583 733 "alias": undefined, 584 734 "arguments": Array [ 585 735 Object { 586 736 "kind": "Argument", 737 + "loc": undefined, 587 738 "name": Object { 588 739 "kind": "Name", 740 + "loc": undefined, 589 741 "value": "pictures", 590 742 }, 591 743 "value": Object { 592 744 "kind": "Variable", 745 + "loc": undefined, 593 746 "name": Object { 594 747 "kind": "Name", 748 + "loc": undefined, 595 749 "value": "pictures", 596 750 }, 597 751 }, ··· 599 753 ], 600 754 "directives": Array [], 601 755 "kind": "Field", 756 + "loc": undefined, 602 757 "name": Object { 603 758 "kind": "Name", 759 + "loc": undefined, 604 760 "value": "uploadProfilePicture", 605 761 }, 606 762 "selectionSet": Object { 607 763 "kind": "SelectionSet", 764 + "loc": undefined, 608 765 "selections": Array [ 609 766 Object { 610 767 "alias": undefined, 611 768 "arguments": Array [], 612 769 "directives": Array [], 613 770 "kind": "Field", 771 + "loc": undefined, 614 772 "name": Object { 615 773 "kind": "Name", 774 + "loc": undefined, 616 775 "value": "location", 617 776 }, 618 777 "selectionSet": undefined, ··· 627 786 "defaultValue": undefined, 628 787 "directives": Array [], 629 788 "kind": "VariableDefinition", 789 + "loc": undefined, 630 790 "type": Object { 631 791 "kind": "ListType", 792 + "loc": undefined, 632 793 "type": Object { 633 794 "kind": "NamedType", 795 + "loc": undefined, 634 796 "name": Object { 635 797 "kind": "Name", 798 + "loc": undefined, 636 799 "value": "File", 637 800 }, 638 801 }, 639 802 }, 640 803 "variable": Object { 641 804 "kind": "Variable", 805 + "loc": undefined, 642 806 "name": Object { 643 807 "kind": "Name", 808 + "loc": undefined, 644 809 "value": "pictures", 645 810 }, 646 811 }, ··· 651 816 "kind": "Document", 652 817 "loc": Object { 653 818 "end": 140, 819 + "source": Source { 820 + "body": " 821 + mutation uploadProfilePictures($pictures: [File]) { 822 + uploadProfilePicture(pictures: $pictures) { 823 + location 824 + } 825 + } 826 + ", 827 + "locationOffset": Object { 828 + "column": 1, 829 + "line": 1, 830 + }, 831 + "name": "gql", 832 + }, 654 833 "start": 0, 655 834 }, 656 835 },
+1 -1
exchanges/multipart-fetch/src/test-utils.ts
··· 1 1 import { 2 + gql, 2 3 GraphQLRequest, 3 4 OperationContext, 4 5 Operation, 5 6 makeOperation, 6 7 } from '@urql/core'; 7 - import gql from 'graphql-tag'; 8 8 9 9 const context: OperationContext = { 10 10 fetchOptions: {
+1 -2
exchanges/persisted-fetch/package.json
··· 56 56 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 57 57 }, 58 58 "devDependencies": { 59 - "graphql": "^15.4.0", 60 - "graphql-tag": "^2.10.1" 59 + "graphql": "^15.4.0" 61 60 }, 62 61 "publishConfig": { 63 62 "access": "public"
+1 -1
exchanges/persisted-fetch/src/test-utils.ts
··· 1 1 import { 2 + gql, 2 3 GraphQLRequest, 3 4 OperationContext, 4 5 Operation, 5 6 makeOperation, 6 7 } from '@urql/core'; 7 - import gql from 'graphql-tag'; 8 8 9 9 const context: OperationContext = { 10 10 fetchOptions: {
+1 -2
exchanges/populate/package.json
··· 56 56 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" 57 57 }, 58 58 "devDependencies": { 59 - "graphql": "^15.4.0", 60 - "graphql-tag": "^2.10.1" 59 + "graphql": "^15.4.0" 61 60 }, 62 61 "publishConfig": { 63 62 "access": "public"
+7 -2
exchanges/populate/src/populateExchange.test.ts
··· 7 7 ASTKindToNode, 8 8 } from 'graphql'; 9 9 10 - import gql from 'graphql-tag'; 11 10 import { fromValue, pipe, fromArray, toArray } from 'wonka'; 12 - import { Client, Operation, OperationContext, makeOperation } from '@urql/core'; 11 + import { 12 + gql, 13 + Client, 14 + Operation, 15 + OperationContext, 16 + makeOperation, 17 + } from '@urql/core'; 13 18 14 19 import { populateExchange } from './populateExchange'; 15 20
+2 -2
exchanges/refocus/src/refocusExchange.test.ts
··· 1 - import gql from 'graphql-tag'; 2 - 3 1 import { pipe, map, makeSubject, publish, tap } from 'wonka'; 4 2 5 3 import { 4 + gql, 6 5 createClient, 7 6 Operation, 8 7 OperationResult, 9 8 ExchangeIO, 10 9 } from '@urql/core'; 10 + 11 11 import { refocusExchange } from './refocusExchange'; 12 12 13 13 const dispatchDebug = jest.fn();
+2 -2
exchanges/request-policy/src/requestPolicyExchange.test.ts
··· 1 - import gql from 'graphql-tag'; 2 - 3 1 import { pipe, map, makeSubject, publish, tap } from 'wonka'; 4 2 5 3 import { 4 + gql, 6 5 createClient, 7 6 Operation, 8 7 OperationResult, 9 8 ExchangeIO, 10 9 } from '@urql/core'; 10 + 11 11 import { requestPolicyExchange } from './requestPolicyExchange'; 12 12 13 13 const dispatchDebug = jest.fn();
+2 -2
exchanges/retry/src/retryExchange.test.ts
··· 1 - import gql from 'graphql-tag'; 2 - 3 1 import { pipe, map, makeSubject, publish, tap } from 'wonka'; 4 2 5 3 import { 4 + gql, 6 5 createClient, 7 6 Operation, 8 7 OperationResult, 9 8 ExchangeIO, 10 9 } from '@urql/core'; 10 + 11 11 import { retryExchange } from './retryExchange'; 12 12 13 13 const dispatchDebug = jest.fn();
-1
package.json
··· 74 74 "execa": "^4.1.0", 75 75 "glob": "^7.1.6", 76 76 "graphql": "^15.4.0", 77 - "graphql-tag": "^2.11.0", 78 77 "husky": "^4.3.0", 79 78 "invariant": "^2.2.4", 80 79 "jest": "^26.6.3",
+1 -2
packages/core/package.json
··· 56 56 "preset": "../../scripts/jest/preset" 57 57 }, 58 58 "devDependencies": { 59 - "graphql": "^15.4.0", 60 - "graphql-tag": "^2.10.1" 59 + "graphql": "^15.4.0" 61 60 }, 62 61 "peerDependencies": { 63 62 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
+1 -1
packages/core/src/client.test.ts
··· 1 1 import { print } from 'graphql'; 2 - import gql from 'graphql-tag'; 3 2 4 3 /** NOTE: Testing in this file is designed to test both the client and its interaction with default Exchanges */ 5 4 6 5 import { Source, map, pipe, subscribe, filter, toArray, tap } from 'wonka'; 6 + import { gql } from './gql'; 7 7 import { Exchange, Operation, OperationResult } from './types'; 8 8 import { createClient } from './client'; 9 9 import { queryOperation } from './test-utils';
+114
packages/core/src/exchanges/__snapshots__/fetch.test.ts.snap
··· 17 17 "kind": "query", 18 18 "operationName": "query", 19 19 "query": Object { 20 + "__key": 3044551916, 20 21 "definitions": Array [ 21 22 Object { 22 23 "directives": Array [], 23 24 "kind": "OperationDefinition", 25 + "loc": undefined, 24 26 "name": Object { 25 27 "kind": "Name", 28 + "loc": undefined, 26 29 "value": "getUser", 27 30 }, 28 31 "operation": "query", 29 32 "selectionSet": Object { 30 33 "kind": "SelectionSet", 34 + "loc": undefined, 31 35 "selections": Array [ 32 36 Object { 33 37 "alias": undefined, 34 38 "arguments": Array [ 35 39 Object { 36 40 "kind": "Argument", 41 + "loc": undefined, 37 42 "name": Object { 38 43 "kind": "Name", 44 + "loc": undefined, 39 45 "value": "name", 40 46 }, 41 47 "value": Object { 42 48 "kind": "Variable", 49 + "loc": undefined, 43 50 "name": Object { 44 51 "kind": "Name", 52 + "loc": undefined, 45 53 "value": "name", 46 54 }, 47 55 }, ··· 49 57 ], 50 58 "directives": Array [], 51 59 "kind": "Field", 60 + "loc": undefined, 52 61 "name": Object { 53 62 "kind": "Name", 63 + "loc": undefined, 54 64 "value": "user", 55 65 }, 56 66 "selectionSet": Object { 57 67 "kind": "SelectionSet", 68 + "loc": undefined, 58 69 "selections": Array [ 59 70 Object { 60 71 "alias": undefined, 61 72 "arguments": Array [], 62 73 "directives": Array [], 63 74 "kind": "Field", 75 + "loc": undefined, 64 76 "name": Object { 65 77 "kind": "Name", 78 + "loc": undefined, 66 79 "value": "id", 67 80 }, 68 81 "selectionSet": undefined, ··· 72 85 "arguments": Array [], 73 86 "directives": Array [], 74 87 "kind": "Field", 88 + "loc": undefined, 75 89 "name": Object { 76 90 "kind": "Name", 91 + "loc": undefined, 77 92 "value": "firstName", 78 93 }, 79 94 "selectionSet": undefined, ··· 83 98 "arguments": Array [], 84 99 "directives": Array [], 85 100 "kind": "Field", 101 + "loc": undefined, 86 102 "name": Object { 87 103 "kind": "Name", 104 + "loc": undefined, 88 105 "value": "lastName", 89 106 }, 90 107 "selectionSet": undefined, ··· 99 116 "defaultValue": undefined, 100 117 "directives": Array [], 101 118 "kind": "VariableDefinition", 119 + "loc": undefined, 102 120 "type": Object { 103 121 "kind": "NamedType", 122 + "loc": undefined, 104 123 "name": Object { 105 124 "kind": "Name", 125 + "loc": undefined, 106 126 "value": "String", 107 127 }, 108 128 }, 109 129 "variable": Object { 110 130 "kind": "Variable", 131 + "loc": undefined, 111 132 "name": Object { 112 133 "kind": "Name", 134 + "loc": undefined, 113 135 "value": "name", 114 136 }, 115 137 }, ··· 120 142 "kind": "Document", 121 143 "loc": Object { 122 144 "end": 124, 145 + "source": Source { 146 + "body": " 147 + query getUser($name: String) { 148 + user(name: $name) { 149 + id 150 + firstName 151 + lastName 152 + } 153 + } 154 + ", 155 + "locationOffset": Object { 156 + "column": 1, 157 + "line": 1, 158 + }, 159 + "name": "gql", 160 + }, 123 161 "start": 0, 124 162 }, 125 163 }, ··· 157 195 "kind": "query", 158 196 "operationName": "query", 159 197 "query": Object { 198 + "__key": 3044551916, 160 199 "definitions": Array [ 161 200 Object { 162 201 "directives": Array [], 163 202 "kind": "OperationDefinition", 203 + "loc": undefined, 164 204 "name": Object { 165 205 "kind": "Name", 206 + "loc": undefined, 166 207 "value": "getUser", 167 208 }, 168 209 "operation": "query", 169 210 "selectionSet": Object { 170 211 "kind": "SelectionSet", 212 + "loc": undefined, 171 213 "selections": Array [ 172 214 Object { 173 215 "alias": undefined, 174 216 "arguments": Array [ 175 217 Object { 176 218 "kind": "Argument", 219 + "loc": undefined, 177 220 "name": Object { 178 221 "kind": "Name", 222 + "loc": undefined, 179 223 "value": "name", 180 224 }, 181 225 "value": Object { 182 226 "kind": "Variable", 227 + "loc": undefined, 183 228 "name": Object { 184 229 "kind": "Name", 230 + "loc": undefined, 185 231 "value": "name", 186 232 }, 187 233 }, ··· 189 235 ], 190 236 "directives": Array [], 191 237 "kind": "Field", 238 + "loc": undefined, 192 239 "name": Object { 193 240 "kind": "Name", 241 + "loc": undefined, 194 242 "value": "user", 195 243 }, 196 244 "selectionSet": Object { 197 245 "kind": "SelectionSet", 246 + "loc": undefined, 198 247 "selections": Array [ 199 248 Object { 200 249 "alias": undefined, 201 250 "arguments": Array [], 202 251 "directives": Array [], 203 252 "kind": "Field", 253 + "loc": undefined, 204 254 "name": Object { 205 255 "kind": "Name", 256 + "loc": undefined, 206 257 "value": "id", 207 258 }, 208 259 "selectionSet": undefined, ··· 212 263 "arguments": Array [], 213 264 "directives": Array [], 214 265 "kind": "Field", 266 + "loc": undefined, 215 267 "name": Object { 216 268 "kind": "Name", 269 + "loc": undefined, 217 270 "value": "firstName", 218 271 }, 219 272 "selectionSet": undefined, ··· 223 276 "arguments": Array [], 224 277 "directives": Array [], 225 278 "kind": "Field", 279 + "loc": undefined, 226 280 "name": Object { 227 281 "kind": "Name", 282 + "loc": undefined, 228 283 "value": "lastName", 229 284 }, 230 285 "selectionSet": undefined, ··· 239 294 "defaultValue": undefined, 240 295 "directives": Array [], 241 296 "kind": "VariableDefinition", 297 + "loc": undefined, 242 298 "type": Object { 243 299 "kind": "NamedType", 300 + "loc": undefined, 244 301 "name": Object { 245 302 "kind": "Name", 303 + "loc": undefined, 246 304 "value": "String", 247 305 }, 248 306 }, 249 307 "variable": Object { 250 308 "kind": "Variable", 309 + "loc": undefined, 251 310 "name": Object { 252 311 "kind": "Name", 312 + "loc": undefined, 253 313 "value": "name", 254 314 }, 255 315 }, ··· 260 320 "kind": "Document", 261 321 "loc": Object { 262 322 "end": 124, 323 + "source": Source { 324 + "body": " 325 + query getUser($name: String) { 326 + user(name: $name) { 327 + id 328 + firstName 329 + lastName 330 + } 331 + } 332 + ", 333 + "locationOffset": Object { 334 + "column": 1, 335 + "line": 1, 336 + }, 337 + "name": "gql", 338 + }, 263 339 "start": 0, 264 340 }, 265 341 }, ··· 299 375 "kind": "query", 300 376 "operationName": "query", 301 377 "query": Object { 378 + "__key": 3044551916, 302 379 "definitions": Array [ 303 380 Object { 304 381 "directives": Array [], 305 382 "kind": "OperationDefinition", 383 + "loc": undefined, 306 384 "name": Object { 307 385 "kind": "Name", 386 + "loc": undefined, 308 387 "value": "getUser", 309 388 }, 310 389 "operation": "query", 311 390 "selectionSet": Object { 312 391 "kind": "SelectionSet", 392 + "loc": undefined, 313 393 "selections": Array [ 314 394 Object { 315 395 "alias": undefined, 316 396 "arguments": Array [ 317 397 Object { 318 398 "kind": "Argument", 399 + "loc": undefined, 319 400 "name": Object { 320 401 "kind": "Name", 402 + "loc": undefined, 321 403 "value": "name", 322 404 }, 323 405 "value": Object { 324 406 "kind": "Variable", 407 + "loc": undefined, 325 408 "name": Object { 326 409 "kind": "Name", 410 + "loc": undefined, 327 411 "value": "name", 328 412 }, 329 413 }, ··· 331 415 ], 332 416 "directives": Array [], 333 417 "kind": "Field", 418 + "loc": undefined, 334 419 "name": Object { 335 420 "kind": "Name", 421 + "loc": undefined, 336 422 "value": "user", 337 423 }, 338 424 "selectionSet": Object { 339 425 "kind": "SelectionSet", 426 + "loc": undefined, 340 427 "selections": Array [ 341 428 Object { 342 429 "alias": undefined, 343 430 "arguments": Array [], 344 431 "directives": Array [], 345 432 "kind": "Field", 433 + "loc": undefined, 346 434 "name": Object { 347 435 "kind": "Name", 436 + "loc": undefined, 348 437 "value": "id", 349 438 }, 350 439 "selectionSet": undefined, ··· 354 443 "arguments": Array [], 355 444 "directives": Array [], 356 445 "kind": "Field", 446 + "loc": undefined, 357 447 "name": Object { 358 448 "kind": "Name", 449 + "loc": undefined, 359 450 "value": "firstName", 360 451 }, 361 452 "selectionSet": undefined, ··· 365 456 "arguments": Array [], 366 457 "directives": Array [], 367 458 "kind": "Field", 459 + "loc": undefined, 368 460 "name": Object { 369 461 "kind": "Name", 462 + "loc": undefined, 370 463 "value": "lastName", 371 464 }, 372 465 "selectionSet": undefined, ··· 381 474 "defaultValue": undefined, 382 475 "directives": Array [], 383 476 "kind": "VariableDefinition", 477 + "loc": undefined, 384 478 "type": Object { 385 479 "kind": "NamedType", 480 + "loc": undefined, 386 481 "name": Object { 387 482 "kind": "Name", 483 + "loc": undefined, 388 484 "value": "String", 389 485 }, 390 486 }, 391 487 "variable": Object { 392 488 "kind": "Variable", 489 + "loc": undefined, 393 490 "name": Object { 394 491 "kind": "Name", 492 + "loc": undefined, 395 493 "value": "name", 396 494 }, 397 495 }, ··· 402 500 "kind": "Document", 403 501 "loc": Object { 404 502 "end": 124, 503 + "source": Source { 504 + "body": " 505 + query getUser($name: String) { 506 + user(name: $name) { 507 + id 508 + firstName 509 + lastName 510 + } 511 + } 512 + ", 513 + "locationOffset": Object { 514 + "column": 1, 515 + "line": 1, 516 + }, 517 + "name": "gql", 518 + }, 405 519 "start": 0, 406 520 }, 407 521 },
+32
packages/core/src/exchanges/__snapshots__/subscription.test.ts.snap
··· 17 17 "kind": "subscription", 18 18 "operationName": "subscription", 19 19 "query": Object { 20 + "__key": 2616620656, 20 21 "definitions": Array [ 21 22 Object { 22 23 "directives": Array [], 23 24 "kind": "OperationDefinition", 25 + "loc": undefined, 24 26 "name": Object { 25 27 "kind": "Name", 28 + "loc": undefined, 26 29 "value": "subscribeToUser", 27 30 }, 28 31 "operation": "subscription", 29 32 "selectionSet": Object { 30 33 "kind": "SelectionSet", 34 + "loc": undefined, 31 35 "selections": Array [ 32 36 Object { 33 37 "alias": undefined, 34 38 "arguments": Array [ 35 39 Object { 36 40 "kind": "Argument", 41 + "loc": undefined, 37 42 "name": Object { 38 43 "kind": "Name", 44 + "loc": undefined, 39 45 "value": "user", 40 46 }, 41 47 "value": Object { 42 48 "kind": "Variable", 49 + "loc": undefined, 43 50 "name": Object { 44 51 "kind": "Name", 52 + "loc": undefined, 45 53 "value": "user", 46 54 }, 47 55 }, ··· 49 57 ], 50 58 "directives": Array [], 51 59 "kind": "Field", 60 + "loc": undefined, 52 61 "name": Object { 53 62 "kind": "Name", 63 + "loc": undefined, 54 64 "value": "user", 55 65 }, 56 66 "selectionSet": Object { 57 67 "kind": "SelectionSet", 68 + "loc": undefined, 58 69 "selections": Array [ 59 70 Object { 60 71 "alias": undefined, 61 72 "arguments": Array [], 62 73 "directives": Array [], 63 74 "kind": "Field", 75 + "loc": undefined, 64 76 "name": Object { 65 77 "kind": "Name", 78 + "loc": undefined, 66 79 "value": "name", 67 80 }, 68 81 "selectionSet": undefined, ··· 77 90 "defaultValue": undefined, 78 91 "directives": Array [], 79 92 "kind": "VariableDefinition", 93 + "loc": undefined, 80 94 "type": Object { 81 95 "kind": "NamedType", 96 + "loc": undefined, 82 97 "name": Object { 83 98 "kind": "Name", 99 + "loc": undefined, 84 100 "value": "String", 85 101 }, 86 102 }, 87 103 "variable": Object { 88 104 "kind": "Variable", 105 + "loc": undefined, 89 106 "name": Object { 90 107 "kind": "Name", 108 + "loc": undefined, 91 109 "value": "user", 92 110 }, 93 111 }, ··· 98 116 "kind": "Document", 99 117 "loc": Object { 100 118 "end": 106, 119 + "source": Source { 120 + "body": " 121 + subscription subscribeToUser($user: String) { 122 + user(user: $user) { 123 + name 124 + } 125 + } 126 + ", 127 + "locationOffset": Object { 128 + "column": 1, 129 + "line": 1, 130 + }, 131 + "name": "gql", 132 + }, 101 133 "start": 0, 102 134 }, 103 135 },
+1 -58
packages/core/src/exchanges/cache.test.ts
··· 20 20 undefinedQueryResponse, 21 21 } from '../test-utils'; 22 22 import { Operation, OperationResult, ExchangeInput } from '../types'; 23 - import { afterMutation, cacheExchange } from './cache'; 23 + import { cacheExchange } from './cache'; 24 24 25 25 const reexecuteOperation = jest.fn(); 26 26 const dispatchDebug = jest.fn(); ··· 175 175 complete(); 176 176 expect(forwardedOperations.length).toBe(2); 177 177 expect(reexecuteOperation).not.toBeCalled(); 178 - }); 179 - 180 - it('retriggers query operation', () => { 181 - const typename = 'ExampleType'; 182 - const resultCache = new Map([[123, queryResponse]]); 183 - const operationCache = { [typename]: new Set([123]) }; 184 - 185 - afterMutation( 186 - resultCache, 187 - operationCache, 188 - exchangeArgs.client, 189 - dispatchDebug 190 - )({ 191 - ...mutationResponse, 192 - data: { 193 - todos: [ 194 - { 195 - id: 1, 196 - __typename: typename, 197 - }, 198 - ], 199 - }, 200 - }); 201 - 202 - expect(reexecuteOperation).toBeCalledTimes(1); 203 - }); 204 - 205 - it('retriggers query operation with additionalTypenames', () => { 206 - const typename = 'ExampleType'; 207 - const resultCache = new Map([[123, queryResponse]]); 208 - const operationCache = { [`${typename}-2`]: new Set([123]) }; 209 - 210 - afterMutation( 211 - resultCache, 212 - operationCache, 213 - exchangeArgs.client, 214 - dispatchDebug 215 - )({ 216 - ...mutationResponse, 217 - operation: { 218 - ...mutationResponse.operation, 219 - context: { 220 - ...mutationResponse.operation.context, 221 - additionalTypenames: [`${typename}-2`], 222 - }, 223 - }, 224 - data: { 225 - todos: [ 226 - { 227 - id: 1, 228 - __typename: typename, 229 - }, 230 - ], 231 - }, 232 - }); 233 - 234 - expect(reexecuteOperation).toBeCalledTimes(1); 235 178 }); 236 179 }); 237 180
+47 -78
packages/core/src/exchanges/cache.ts
··· 2 2 import { filter, map, merge, pipe, share, tap } from 'wonka'; 3 3 4 4 import { Client } from '../client'; 5 - import { Exchange, Operation, OperationResult, ExchangeInput } from '../types'; 5 + import { Exchange, Operation, OperationResult } from '../types'; 6 6 7 7 import { 8 8 makeOperation, ··· 30 30 formattedOperation.query = formatDocument(operation.query); 31 31 return formattedOperation; 32 32 }; 33 - 34 - const handleAfterMutation = afterMutation( 35 - resultCache, 36 - operationCache, 37 - client, 38 - dispatchDebug 39 - ); 40 - 41 - const handleAfterQuery = afterQuery(resultCache, operationCache); 42 33 43 34 const isOperationCached = (operation: Operation) => { 44 35 const { ··· 109 100 ), 110 101 forward, 111 102 tap(response => { 112 - if (response.operation && response.operation.kind === 'mutation') { 113 - handleAfterMutation(response); 114 - } else if (response.operation && response.operation.kind === 'query') { 115 - handleAfterQuery(response); 103 + let { operation } = response; 104 + if (!operation) return; 105 + 106 + const typenames = collectTypesFromResponse(response.data).concat( 107 + operation.context.additionalTypenames || [] 108 + ); 109 + 110 + // Invalidates the cache given a mutation's response 111 + if (response.operation.kind === 'mutation') { 112 + const pendingOperations = new Set<number>(); 113 + 114 + dispatchDebug({ 115 + type: 'cacheInvalidation', 116 + message: `The following typenames have been invalidated: ${typenames}`, 117 + operation, 118 + data: { typenames, response }, 119 + }); 120 + 121 + for (let i = 0; i < typenames.length; i++) { 122 + const typeName = typenames[i]; 123 + const operations = 124 + operationCache[typeName] || 125 + (operationCache[typeName] = new Set()); 126 + operations.forEach(key => { 127 + pendingOperations.add(key); 128 + }); 129 + operations.clear(); 130 + } 131 + 132 + pendingOperations.forEach(key => { 133 + if (resultCache.has(key)) { 134 + operation = (resultCache.get(key) as OperationResult).operation; 135 + resultCache.delete(key); 136 + reexecuteOperation(client, operation); 137 + } 138 + }); 139 + // Mark typenames on typenameInvalidate for early invalidation 140 + } else if (operation.kind === 'query' && response.data) { 141 + resultCache.set(operation.key, response); 142 + for (let i = 0; i < typenames.length; i++) { 143 + const typeName = typenames[i]; 144 + const operations = 145 + operationCache[typeName] || 146 + (operationCache[typeName] = new Set()); 147 + operations.add(operation.key); 148 + } 116 149 } 117 150 }) 118 151 ); ··· 130 163 }) 131 164 ); 132 165 }; 133 - 134 - // Invalidates the cache given a mutation's response 135 - export const afterMutation = ( 136 - resultCache: ResultCache, 137 - operationCache: OperationCache, 138 - client: Client, 139 - dispatchDebug: ExchangeInput['dispatchDebug'] 140 - ) => (response: OperationResult) => { 141 - const pendingOperations = new Set<number>(); 142 - const { additionalTypenames } = response.operation.context; 143 - 144 - const typenames = [ 145 - ...collectTypesFromResponse(response.data), 146 - ...(additionalTypenames || []), 147 - ]; 148 - 149 - dispatchDebug({ 150 - type: 'cacheInvalidation', 151 - message: `The following typenames have been invalidated: ${typenames}`, 152 - operation: response.operation, 153 - data: { typenames, response }, 154 - }); 155 - 156 - typenames.forEach(typeName => { 157 - const operations = 158 - operationCache[typeName] || (operationCache[typeName] = new Set()); 159 - operations.forEach(key => { 160 - pendingOperations.add(key); 161 - }); 162 - operations.clear(); 163 - }); 164 - 165 - pendingOperations.forEach(key => { 166 - if (resultCache.has(key)) { 167 - const operation = (resultCache.get(key) as OperationResult).operation; 168 - resultCache.delete(key); 169 - reexecuteOperation(client, operation); 170 - } 171 - }); 172 - }; 173 - 174 - // Mark typenames on typenameInvalidate for early invalidation 175 - const afterQuery = ( 176 - resultCache: ResultCache, 177 - operationCache: OperationCache 178 - ) => (response: OperationResult) => { 179 - const { operation, data, error } = response; 180 - const { additionalTypenames } = operation.context; 181 - 182 - if (data === undefined || data === null) { 183 - return; 184 - } 185 - 186 - resultCache.set(operation.key, { operation, data, error }); 187 - 188 - [ 189 - ...collectTypesFromResponse(response.data), 190 - ...(additionalTypenames || []), 191 - ].forEach(typeName => { 192 - const operations = 193 - operationCache[typeName] || (operationCache[typeName] = new Set()); 194 - operations.add(operation.key); 195 - }); 196 - };
+60
packages/core/src/gql.test.ts
··· 1 + import { Source, parse, print } from 'graphql'; 2 + import { gql } from './gql'; 3 + import { keyDocument } from './utils'; 4 + 5 + it('parses GraphQL Documents', () => { 6 + expect(gql('{ test }').definitions).toEqual( 7 + parse('{ test }', { noLocation: true }).definitions 8 + ); 9 + expect(gql('{ test }')).toBe(keyDocument('{ test }')); 10 + 11 + expect(gql('{ test }').loc).toEqual({ 12 + start: 0, 13 + end: 8, 14 + source: new Source('{ test }', 'gql'), 15 + }); 16 + }); 17 + 18 + it('interpolates nested GraphQL Documents', () => { 19 + expect( 20 + print( 21 + gql` 22 + query { 23 + ...Query 24 + } 25 + 26 + ${gql` 27 + fragment Query on Query { 28 + field 29 + } 30 + `} 31 + ` 32 + ) 33 + ).toMatchInlineSnapshot(` 34 + "{ 35 + ...Query 36 + } 37 + 38 + fragment Query on Query { 39 + field 40 + } 41 + " 42 + `); 43 + }); 44 + 45 + it('interpolates strings', () => { 46 + expect( 47 + print( 48 + gql` 49 + query { 50 + ${'field'} 51 + } 52 + ` 53 + ) 54 + ).toMatchInlineSnapshot(` 55 + "{ 56 + field 57 + } 58 + " 59 + `); 60 + });
+64
packages/core/src/gql.ts
··· 1 + /* eslint-disable prefer-rest-params */ 2 + import { TypedDocumentNode } from '@graphql-typed-document-node/core'; 3 + import { Source, Location, DocumentNode, Kind, print } from 'graphql'; 4 + import { keyDocument } from './utils'; 5 + 6 + type WritableDocumentNode = { 7 + -readonly [K in keyof DocumentNode]: DocumentNode[K]; 8 + }; 9 + 10 + function gql<Data = any, Variables = object>( 11 + strings: TemplateStringsArray, 12 + ...interpolations: Array<TypedDocumentNode | DocumentNode | string> 13 + ): TypedDocumentNode<Data, Variables>; 14 + 15 + function gql<Data = any, Variables = object>( 16 + string: string 17 + ): TypedDocumentNode<Data, Variables>; 18 + 19 + function gql(/* arguments */) { 20 + let body: string = Array.isArray(arguments[0]) 21 + ? arguments[0][0] 22 + : arguments[0] || ''; 23 + for (let i = 1; i < arguments.length; i++) { 24 + const value = arguments[i]; 25 + body += 26 + value && value.kind === Kind.DOCUMENT 27 + ? value.loc 28 + ? value.loc.source.body 29 + : print(value) 30 + : value; 31 + body += arguments[0][i]; 32 + } 33 + 34 + const doc = keyDocument(body); 35 + if (process.env.NODE_ENV !== 'production') { 36 + const fragmentNames = new Set(); 37 + for (let i = 0; i < doc.definitions.length; i++) { 38 + const definition = doc.definitions[i]; 39 + if (definition.kind === Kind.FRAGMENT_DEFINITION) { 40 + const name = definition.name.value; 41 + if (fragmentNames.has(name)) { 42 + console.warn( 43 + '[WARNING: Duplicate Fragment] A fragment with name `' + 44 + name + 45 + '` already exists in this document.\n' + 46 + 'While fragment names may not be unique across your source, each name must be unique per document.' 47 + ); 48 + } else { 49 + fragmentNames.add(name); 50 + } 51 + } 52 + } 53 + } 54 + 55 + (doc as WritableDocumentNode).loc = { 56 + start: 0, 57 + end: body.length, 58 + source: new Source(body, 'gql'), 59 + } as Location; 60 + 61 + return doc; 62 + } 63 + 64 + export { gql };
+1
packages/core/src/index.ts
··· 1 1 export { TypedDocumentNode } from '@graphql-typed-document-node/core'; 2 + export { gql } from './gql'; 2 3 3 4 export * from './client'; 4 5 export * from './exchanges';
+190
packages/core/src/internal/__snapshots__/fetchSource.test.ts.snap
··· 17 17 "kind": "query", 18 18 "operationName": "query", 19 19 "query": Object { 20 + "__key": 3044551916, 20 21 "definitions": Array [ 21 22 Object { 22 23 "directives": Array [], 23 24 "kind": "OperationDefinition", 25 + "loc": undefined, 24 26 "name": Object { 25 27 "kind": "Name", 28 + "loc": undefined, 26 29 "value": "getUser", 27 30 }, 28 31 "operation": "query", 29 32 "selectionSet": Object { 30 33 "kind": "SelectionSet", 34 + "loc": undefined, 31 35 "selections": Array [ 32 36 Object { 33 37 "alias": undefined, 34 38 "arguments": Array [ 35 39 Object { 36 40 "kind": "Argument", 41 + "loc": undefined, 37 42 "name": Object { 38 43 "kind": "Name", 44 + "loc": undefined, 39 45 "value": "name", 40 46 }, 41 47 "value": Object { 42 48 "kind": "Variable", 49 + "loc": undefined, 43 50 "name": Object { 44 51 "kind": "Name", 52 + "loc": undefined, 45 53 "value": "name", 46 54 }, 47 55 }, ··· 49 57 ], 50 58 "directives": Array [], 51 59 "kind": "Field", 60 + "loc": undefined, 52 61 "name": Object { 53 62 "kind": "Name", 63 + "loc": undefined, 54 64 "value": "user", 55 65 }, 56 66 "selectionSet": Object { 57 67 "kind": "SelectionSet", 68 + "loc": undefined, 58 69 "selections": Array [ 59 70 Object { 60 71 "alias": undefined, 61 72 "arguments": Array [], 62 73 "directives": Array [], 63 74 "kind": "Field", 75 + "loc": undefined, 64 76 "name": Object { 65 77 "kind": "Name", 78 + "loc": undefined, 66 79 "value": "id", 67 80 }, 68 81 "selectionSet": undefined, ··· 72 85 "arguments": Array [], 73 86 "directives": Array [], 74 87 "kind": "Field", 88 + "loc": undefined, 75 89 "name": Object { 76 90 "kind": "Name", 91 + "loc": undefined, 77 92 "value": "firstName", 78 93 }, 79 94 "selectionSet": undefined, ··· 83 98 "arguments": Array [], 84 99 "directives": Array [], 85 100 "kind": "Field", 101 + "loc": undefined, 86 102 "name": Object { 87 103 "kind": "Name", 104 + "loc": undefined, 88 105 "value": "lastName", 89 106 }, 90 107 "selectionSet": undefined, ··· 99 116 "defaultValue": undefined, 100 117 "directives": Array [], 101 118 "kind": "VariableDefinition", 119 + "loc": undefined, 102 120 "type": Object { 103 121 "kind": "NamedType", 122 + "loc": undefined, 104 123 "name": Object { 105 124 "kind": "Name", 125 + "loc": undefined, 106 126 "value": "String", 107 127 }, 108 128 }, 109 129 "variable": Object { 110 130 "kind": "Variable", 131 + "loc": undefined, 111 132 "name": Object { 112 133 "kind": "Name", 134 + "loc": undefined, 113 135 "value": "name", 114 136 }, 115 137 }, ··· 120 142 "kind": "Document", 121 143 "loc": Object { 122 144 "end": 124, 145 + "source": Source { 146 + "body": " 147 + query getUser($name: String) { 148 + user(name: $name) { 149 + id 150 + firstName 151 + lastName 152 + } 153 + } 154 + ", 155 + "locationOffset": Object { 156 + "column": 1, 157 + "line": 1, 158 + }, 159 + "name": "gql", 160 + }, 123 161 "start": 0, 124 162 }, 125 163 }, ··· 147 185 "kind": "query", 148 186 "operationName": "query", 149 187 "query": Object { 188 + "__key": 3044551916, 150 189 "definitions": Array [ 151 190 Object { 152 191 "directives": Array [], 153 192 "kind": "OperationDefinition", 193 + "loc": undefined, 154 194 "name": Object { 155 195 "kind": "Name", 196 + "loc": undefined, 156 197 "value": "getUser", 157 198 }, 158 199 "operation": "query", 159 200 "selectionSet": Object { 160 201 "kind": "SelectionSet", 202 + "loc": undefined, 161 203 "selections": Array [ 162 204 Object { 163 205 "alias": undefined, 164 206 "arguments": Array [ 165 207 Object { 166 208 "kind": "Argument", 209 + "loc": undefined, 167 210 "name": Object { 168 211 "kind": "Name", 212 + "loc": undefined, 169 213 "value": "name", 170 214 }, 171 215 "value": Object { 172 216 "kind": "Variable", 217 + "loc": undefined, 173 218 "name": Object { 174 219 "kind": "Name", 220 + "loc": undefined, 175 221 "value": "name", 176 222 }, 177 223 }, ··· 179 225 ], 180 226 "directives": Array [], 181 227 "kind": "Field", 228 + "loc": undefined, 182 229 "name": Object { 183 230 "kind": "Name", 231 + "loc": undefined, 184 232 "value": "user", 185 233 }, 186 234 "selectionSet": Object { 187 235 "kind": "SelectionSet", 236 + "loc": undefined, 188 237 "selections": Array [ 189 238 Object { 190 239 "alias": undefined, 191 240 "arguments": Array [], 192 241 "directives": Array [], 193 242 "kind": "Field", 243 + "loc": undefined, 194 244 "name": Object { 195 245 "kind": "Name", 246 + "loc": undefined, 196 247 "value": "id", 197 248 }, 198 249 "selectionSet": undefined, ··· 202 253 "arguments": Array [], 203 254 "directives": Array [], 204 255 "kind": "Field", 256 + "loc": undefined, 205 257 "name": Object { 206 258 "kind": "Name", 259 + "loc": undefined, 207 260 "value": "firstName", 208 261 }, 209 262 "selectionSet": undefined, ··· 213 266 "arguments": Array [], 214 267 "directives": Array [], 215 268 "kind": "Field", 269 + "loc": undefined, 216 270 "name": Object { 217 271 "kind": "Name", 272 + "loc": undefined, 218 273 "value": "lastName", 219 274 }, 220 275 "selectionSet": undefined, ··· 229 284 "defaultValue": undefined, 230 285 "directives": Array [], 231 286 "kind": "VariableDefinition", 287 + "loc": undefined, 232 288 "type": Object { 233 289 "kind": "NamedType", 290 + "loc": undefined, 234 291 "name": Object { 235 292 "kind": "Name", 293 + "loc": undefined, 236 294 "value": "String", 237 295 }, 238 296 }, 239 297 "variable": Object { 240 298 "kind": "Variable", 299 + "loc": undefined, 241 300 "name": Object { 242 301 "kind": "Name", 302 + "loc": undefined, 243 303 "value": "name", 244 304 }, 245 305 }, ··· 250 310 "kind": "Document", 251 311 "loc": Object { 252 312 "end": 124, 313 + "source": Source { 314 + "body": " 315 + query getUser($name: String) { 316 + user(name: $name) { 317 + id 318 + firstName 319 + lastName 320 + } 321 + } 322 + ", 323 + "locationOffset": Object { 324 + "column": 1, 325 + "line": 1, 326 + }, 327 + "name": "gql", 328 + }, 253 329 "start": 0, 254 330 }, 255 331 }, ··· 277 353 "kind": "query", 278 354 "operationName": "query", 279 355 "query": Object { 356 + "__key": 3044551916, 280 357 "definitions": Array [ 281 358 Object { 282 359 "directives": Array [], 283 360 "kind": "OperationDefinition", 361 + "loc": undefined, 284 362 "name": Object { 285 363 "kind": "Name", 364 + "loc": undefined, 286 365 "value": "getUser", 287 366 }, 288 367 "operation": "query", 289 368 "selectionSet": Object { 290 369 "kind": "SelectionSet", 370 + "loc": undefined, 291 371 "selections": Array [ 292 372 Object { 293 373 "alias": undefined, 294 374 "arguments": Array [ 295 375 Object { 296 376 "kind": "Argument", 377 + "loc": undefined, 297 378 "name": Object { 298 379 "kind": "Name", 380 + "loc": undefined, 299 381 "value": "name", 300 382 }, 301 383 "value": Object { 302 384 "kind": "Variable", 385 + "loc": undefined, 303 386 "name": Object { 304 387 "kind": "Name", 388 + "loc": undefined, 305 389 "value": "name", 306 390 }, 307 391 }, ··· 309 393 ], 310 394 "directives": Array [], 311 395 "kind": "Field", 396 + "loc": undefined, 312 397 "name": Object { 313 398 "kind": "Name", 399 + "loc": undefined, 314 400 "value": "user", 315 401 }, 316 402 "selectionSet": Object { 317 403 "kind": "SelectionSet", 404 + "loc": undefined, 318 405 "selections": Array [ 319 406 Object { 320 407 "alias": undefined, 321 408 "arguments": Array [], 322 409 "directives": Array [], 323 410 "kind": "Field", 411 + "loc": undefined, 324 412 "name": Object { 325 413 "kind": "Name", 414 + "loc": undefined, 326 415 "value": "id", 327 416 }, 328 417 "selectionSet": undefined, ··· 332 421 "arguments": Array [], 333 422 "directives": Array [], 334 423 "kind": "Field", 424 + "loc": undefined, 335 425 "name": Object { 336 426 "kind": "Name", 427 + "loc": undefined, 337 428 "value": "firstName", 338 429 }, 339 430 "selectionSet": undefined, ··· 343 434 "arguments": Array [], 344 435 "directives": Array [], 345 436 "kind": "Field", 437 + "loc": undefined, 346 438 "name": Object { 347 439 "kind": "Name", 440 + "loc": undefined, 348 441 "value": "lastName", 349 442 }, 350 443 "selectionSet": undefined, ··· 359 452 "defaultValue": undefined, 360 453 "directives": Array [], 361 454 "kind": "VariableDefinition", 455 + "loc": undefined, 362 456 "type": Object { 363 457 "kind": "NamedType", 458 + "loc": undefined, 364 459 "name": Object { 365 460 "kind": "Name", 461 + "loc": undefined, 366 462 "value": "String", 367 463 }, 368 464 }, 369 465 "variable": Object { 370 466 "kind": "Variable", 467 + "loc": undefined, 371 468 "name": Object { 372 469 "kind": "Name", 470 + "loc": undefined, 373 471 "value": "name", 374 472 }, 375 473 }, ··· 380 478 "kind": "Document", 381 479 "loc": Object { 382 480 "end": 124, 481 + "source": Source { 482 + "body": " 483 + query getUser($name: String) { 484 + user(name: $name) { 485 + id 486 + firstName 487 + lastName 488 + } 489 + } 490 + ", 491 + "locationOffset": Object { 492 + "column": 1, 493 + "line": 1, 494 + }, 495 + "name": "gql", 496 + }, 383 497 "start": 0, 384 498 }, 385 499 }, ··· 411 525 "kind": "query", 412 526 "operationName": "query", 413 527 "query": Object { 528 + "__key": 3044551916, 414 529 "definitions": Array [ 415 530 Object { 416 531 "directives": Array [], 417 532 "kind": "OperationDefinition", 533 + "loc": undefined, 418 534 "name": Object { 419 535 "kind": "Name", 536 + "loc": undefined, 420 537 "value": "getUser", 421 538 }, 422 539 "operation": "query", 423 540 "selectionSet": Object { 424 541 "kind": "SelectionSet", 542 + "loc": undefined, 425 543 "selections": Array [ 426 544 Object { 427 545 "alias": undefined, 428 546 "arguments": Array [ 429 547 Object { 430 548 "kind": "Argument", 549 + "loc": undefined, 431 550 "name": Object { 432 551 "kind": "Name", 552 + "loc": undefined, 433 553 "value": "name", 434 554 }, 435 555 "value": Object { 436 556 "kind": "Variable", 557 + "loc": undefined, 437 558 "name": Object { 438 559 "kind": "Name", 560 + "loc": undefined, 439 561 "value": "name", 440 562 }, 441 563 }, ··· 443 565 ], 444 566 "directives": Array [], 445 567 "kind": "Field", 568 + "loc": undefined, 446 569 "name": Object { 447 570 "kind": "Name", 571 + "loc": undefined, 448 572 "value": "user", 449 573 }, 450 574 "selectionSet": Object { 451 575 "kind": "SelectionSet", 576 + "loc": undefined, 452 577 "selections": Array [ 453 578 Object { 454 579 "alias": undefined, 455 580 "arguments": Array [], 456 581 "directives": Array [], 457 582 "kind": "Field", 583 + "loc": undefined, 458 584 "name": Object { 459 585 "kind": "Name", 586 + "loc": undefined, 460 587 "value": "id", 461 588 }, 462 589 "selectionSet": undefined, ··· 466 593 "arguments": Array [], 467 594 "directives": Array [], 468 595 "kind": "Field", 596 + "loc": undefined, 469 597 "name": Object { 470 598 "kind": "Name", 599 + "loc": undefined, 471 600 "value": "firstName", 472 601 }, 473 602 "selectionSet": undefined, ··· 477 606 "arguments": Array [], 478 607 "directives": Array [], 479 608 "kind": "Field", 609 + "loc": undefined, 480 610 "name": Object { 481 611 "kind": "Name", 612 + "loc": undefined, 482 613 "value": "lastName", 483 614 }, 484 615 "selectionSet": undefined, ··· 493 624 "defaultValue": undefined, 494 625 "directives": Array [], 495 626 "kind": "VariableDefinition", 627 + "loc": undefined, 496 628 "type": Object { 497 629 "kind": "NamedType", 630 + "loc": undefined, 498 631 "name": Object { 499 632 "kind": "Name", 633 + "loc": undefined, 500 634 "value": "String", 501 635 }, 502 636 }, 503 637 "variable": Object { 504 638 "kind": "Variable", 639 + "loc": undefined, 505 640 "name": Object { 506 641 "kind": "Name", 642 + "loc": undefined, 507 643 "value": "name", 508 644 }, 509 645 }, ··· 514 650 "kind": "Document", 515 651 "loc": Object { 516 652 "end": 124, 653 + "source": Source { 654 + "body": " 655 + query getUser($name: String) { 656 + user(name: $name) { 657 + id 658 + firstName 659 + lastName 660 + } 661 + } 662 + ", 663 + "locationOffset": Object { 664 + "column": 1, 665 + "line": 1, 666 + }, 667 + "name": "gql", 668 + }, 517 669 "start": 0, 518 670 }, 519 671 }, ··· 561 713 "kind": "query", 562 714 "operationName": "query", 563 715 "query": Object { 716 + "__key": 3044551916, 564 717 "definitions": Array [ 565 718 Object { 566 719 "directives": Array [], 567 720 "kind": "OperationDefinition", 721 + "loc": undefined, 568 722 "name": Object { 569 723 "kind": "Name", 724 + "loc": undefined, 570 725 "value": "getUser", 571 726 }, 572 727 "operation": "query", 573 728 "selectionSet": Object { 574 729 "kind": "SelectionSet", 730 + "loc": undefined, 575 731 "selections": Array [ 576 732 Object { 577 733 "alias": undefined, 578 734 "arguments": Array [ 579 735 Object { 580 736 "kind": "Argument", 737 + "loc": undefined, 581 738 "name": Object { 582 739 "kind": "Name", 740 + "loc": undefined, 583 741 "value": "name", 584 742 }, 585 743 "value": Object { 586 744 "kind": "Variable", 745 + "loc": undefined, 587 746 "name": Object { 588 747 "kind": "Name", 748 + "loc": undefined, 589 749 "value": "name", 590 750 }, 591 751 }, ··· 593 753 ], 594 754 "directives": Array [], 595 755 "kind": "Field", 756 + "loc": undefined, 596 757 "name": Object { 597 758 "kind": "Name", 759 + "loc": undefined, 598 760 "value": "user", 599 761 }, 600 762 "selectionSet": Object { 601 763 "kind": "SelectionSet", 764 + "loc": undefined, 602 765 "selections": Array [ 603 766 Object { 604 767 "alias": undefined, 605 768 "arguments": Array [], 606 769 "directives": Array [], 607 770 "kind": "Field", 771 + "loc": undefined, 608 772 "name": Object { 609 773 "kind": "Name", 774 + "loc": undefined, 610 775 "value": "id", 611 776 }, 612 777 "selectionSet": undefined, ··· 616 781 "arguments": Array [], 617 782 "directives": Array [], 618 783 "kind": "Field", 784 + "loc": undefined, 619 785 "name": Object { 620 786 "kind": "Name", 787 + "loc": undefined, 621 788 "value": "firstName", 622 789 }, 623 790 "selectionSet": undefined, ··· 627 794 "arguments": Array [], 628 795 "directives": Array [], 629 796 "kind": "Field", 797 + "loc": undefined, 630 798 "name": Object { 631 799 "kind": "Name", 800 + "loc": undefined, 632 801 "value": "lastName", 633 802 }, 634 803 "selectionSet": undefined, ··· 643 812 "defaultValue": undefined, 644 813 "directives": Array [], 645 814 "kind": "VariableDefinition", 815 + "loc": undefined, 646 816 "type": Object { 647 817 "kind": "NamedType", 818 + "loc": undefined, 648 819 "name": Object { 649 820 "kind": "Name", 821 + "loc": undefined, 650 822 "value": "String", 651 823 }, 652 824 }, 653 825 "variable": Object { 654 826 "kind": "Variable", 827 + "loc": undefined, 655 828 "name": Object { 656 829 "kind": "Name", 830 + "loc": undefined, 657 831 "value": "name", 658 832 }, 659 833 }, ··· 664 838 "kind": "Document", 665 839 "loc": Object { 666 840 "end": 124, 841 + "source": Source { 842 + "body": " 843 + query getUser($name: String) { 844 + user(name: $name) { 845 + id 846 + firstName 847 + lastName 848 + } 849 + } 850 + ", 851 + "locationOffset": Object { 852 + "column": 1, 853 + "line": 1, 854 + }, 855 + "name": "gql", 856 + }, 667 857 "start": 0, 668 858 }, 669 859 },
+1 -1
packages/core/src/test-utils/samples.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '../gql'; 2 2 3 3 import { 4 4 ExecutionResult,
+1 -1
packages/core/src/utils/request.test.ts
··· 1 1 import { parse, print } from 'graphql'; 2 - import gql from 'graphql-tag'; 2 + import { gql } from '../gql'; 3 3 import { createRequest } from './request'; 4 4 5 5 it('should hash identical queries identically', () => {
+1 -2
packages/introspection/package.json
··· 48 48 "preset": "../../scripts/jest/preset" 49 49 }, 50 50 "devDependencies": { 51 - "graphql": "^15.4.0", 52 - "graphql-tag": "^2.10.1" 51 + "graphql": "^15.4.0" 53 52 }, 54 53 "peerDependencies": { 55 54 "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
-1
packages/next-urql/package.json
··· 42 42 "enzyme": "^3.11.0", 43 43 "enzyme-adapter-react-16": "^1.15.2", 44 44 "graphql": "^15.4.0", 45 - "graphql-tag": "^2.10.3", 46 45 "react": "^17.0.1", 47 46 "react-dom": "^17.0.1", 48 47 "react-is": "^17.0.1"
-1
packages/preact-urql/package.json
··· 53 53 "devDependencies": { 54 54 "@testing-library/preact": "^2.0.0", 55 55 "graphql": "^15.4.0", 56 - "graphql-tag": "^2.10.1", 57 56 "preact": "^10.5.5" 58 57 }, 59 58 "peerDependencies": {
+2 -2
packages/preact-urql/src/hooks/useMutation.test.tsx
··· 1 1 import { FunctionalComponent as FC, h } from 'preact'; 2 2 import { render, cleanup, act } from '@testing-library/preact'; 3 3 import { print } from 'graphql'; 4 - import gql from 'graphql-tag'; 4 + import { gql } from '@urql/core'; 5 5 import { useMutation } from './useMutation'; 6 6 import { fromValue, delay, pipe } from 'wonka'; 7 7 import { Provider } from '../context'; ··· 62 62 const call = client.executeMutation.mock.calls[0][0]; 63 63 expect(state).toHaveProperty('fetching', true); 64 64 expect(client.executeMutation).toBeCalledTimes(1); 65 - expect(print(call.query)).toBe(print(gql([props.query]))); 65 + expect(print(call.query)).toBe(print(gql(props.query))); 66 66 expect(call).toHaveProperty('variables', vars); 67 67 }); 68 68
-1
packages/react-urql/package.json
··· 47 47 "@types/react": "^16.9.56", 48 48 "@types/react-test-renderer": "^16.9.3", 49 49 "graphql": "^15.4.0", 50 - "graphql-tag": "^2.10.1", 51 50 "react": "^17.0.1", 52 51 "react-dom": "^17.0.1", 53 52 "react-is": "^17.0.1",
+2 -2
packages/react-urql/src/hooks/useMutation.test.tsx
··· 16 16 }); 17 17 18 18 import { print } from 'graphql'; 19 - import gql from 'graphql-tag'; 19 + import { gql } from '@urql/core'; 20 20 import React, { FC } from 'react'; 21 21 import renderer, { act } from 'react-test-renderer'; 22 22 ··· 89 89 }); 90 90 91 91 const call = client.executeMutation.mock.calls[0][0]; 92 - expect(print(call.query)).toBe(print(gql([props.query]))); 92 + expect(print(call.query)).toBe(print(gql(props.query))); 93 93 }); 94 94 95 95 it('calls executeMutation with variables', () => {
+1 -1
packages/react-urql/src/hooks/useRequest.test.ts
··· 1 - import gql from 'graphql-tag'; 1 + import { gql } from '@urql/core'; 2 2 import { renderHook } from '@testing-library/react-hooks'; 3 3 import { useRequest } from './useRequest'; 4 4
+1 -1
packages/react-urql/src/test-utils/ssr.test.tsx
··· 1 1 import React from 'react'; 2 - import gql from 'graphql-tag'; 3 2 import prepass from 'react-ssr-prepass'; 4 3 import { never, publish, filter, delay, pipe, map } from 'wonka'; 5 4 6 5 import { 6 + gql, 7 7 createClient, 8 8 Exchange, 9 9 dedupExchange,
+1 -6
yarn.lock
··· 2842 2842 "@typescript-eslint/types" "4.6.1" 2843 2843 eslint-visitor-keys "^2.0.0" 2844 2844 2845 - "@urql/devtools@^2.0.2": 2845 + "@urql/devtools@>=2.0.0": 2846 2846 version "2.0.2" 2847 2847 resolved "https://registry.yarnpkg.com/@urql/devtools/-/devtools-2.0.2.tgz#0991bc3bb09444b162ef56518b76f64f286954fc" 2848 2848 integrity sha512-f3gIx4NDOuWdXC54m4VQlLKNtYHl6PITSEqexH6xiktzvH7QcwS5hNPg0Fkki8cas/DZtkmDpwxNV1uRZ5xlvA== ··· 8122 8122 version "1.0.4" 8123 8123 resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e" 8124 8124 integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ== 8125 - 8126 - graphql-tag@^2.10.1, graphql-tag@^2.10.3, graphql-tag@^2.11.0: 8127 - version "2.11.0" 8128 - resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.11.0.tgz#1deb53a01c46a7eb401d6cb59dec86fa1cccbffd" 8129 - integrity sha512-VmsD5pJqWJnQZMUeRwrDhfgoyqcfwEkvtpANqcoUG8/tOLkwNgU9mzub/Mc78OJMhHjx7gfAMTxzdG43VGg3bA== 8130 8125 8131 8126 graphql@^15.1.0, graphql@^15.4.0: 8132 8127 version "15.4.0"