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.

chore(multipart): Delete multipart-fetch exchange folder (#3119)

authored by

Phil Pluckthun and committed by
GitHub
02e1fd72 16b9023f

-1380
-166
exchanges/multipart-fetch/CHANGELOG.md
··· 1 - # @urql/exchange-multipart-fetch 2 - 3 - ## 1.1.0 4 - 5 - ### Minor Changes 6 - 7 - - Update exchanges to drop redundant `share` calls, since `@urql/core`’s `composeExchanges` utility now automatically does so for us 8 - Submitted by [@kitten](https://github.com/kitten) (See [#3082](https://github.com/urql-graphql/urql/pull/3082)) 9 - 10 - ### Patch Changes 11 - 12 - - Upgrade to `wonka@^6.3.0` 13 - Submitted by [@kitten](https://github.com/kitten) (See [#3104](https://github.com/urql-graphql/urql/pull/3104)) 14 - - Deprecate `@urql/exchange-multipart-fetch` as behaviour has been absorbed into `@urql/core`. If you're using the `multipartFetchExchange`, you should now be able to simply remove it 15 - Submitted by [@kitten](https://github.com/kitten) (See [#3051](https://github.com/urql-graphql/urql/pull/3051)) 16 - - Updated dependencies (See [#3101](https://github.com/urql-graphql/urql/pull/3101), [#3033](https://github.com/urql-graphql/urql/pull/3033), [#3054](https://github.com/urql-graphql/urql/pull/3054), [#3053](https://github.com/urql-graphql/urql/pull/3053), [#3060](https://github.com/urql-graphql/urql/pull/3060), [#3081](https://github.com/urql-graphql/urql/pull/3081), [#3039](https://github.com/urql-graphql/urql/pull/3039), [#3104](https://github.com/urql-graphql/urql/pull/3104), [#3082](https://github.com/urql-graphql/urql/pull/3082), [#3097](https://github.com/urql-graphql/urql/pull/3097), [#3061](https://github.com/urql-graphql/urql/pull/3061), [#3055](https://github.com/urql-graphql/urql/pull/3055), [#3085](https://github.com/urql-graphql/urql/pull/3085), [#3079](https://github.com/urql-graphql/urql/pull/3079), [#3087](https://github.com/urql-graphql/urql/pull/3087), [#3059](https://github.com/urql-graphql/urql/pull/3059), [#3055](https://github.com/urql-graphql/urql/pull/3055), [#3057](https://github.com/urql-graphql/urql/pull/3057), [#3050](https://github.com/urql-graphql/urql/pull/3050), [#3062](https://github.com/urql-graphql/urql/pull/3062), [#3051](https://github.com/urql-graphql/urql/pull/3051), [#3043](https://github.com/urql-graphql/urql/pull/3043), [#3063](https://github.com/urql-graphql/urql/pull/3063), [#3054](https://github.com/urql-graphql/urql/pull/3054), [#3102](https://github.com/urql-graphql/urql/pull/3102), [#3097](https://github.com/urql-graphql/urql/pull/3097), [#3106](https://github.com/urql-graphql/urql/pull/3106), [#3058](https://github.com/urql-graphql/urql/pull/3058), and [#3062](https://github.com/urql-graphql/urql/pull/3062)) 17 - - @urql/core@4.0.0 18 - 19 - ## 1.0.1 20 - 21 - ### Patch Changes 22 - 23 - - ⚠️ Fix issue where we construct the fetchOptions before constructing the url resulting in our overflow fix not working, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#2653](https://github.com/FormidableLabs/urql/pull/2653)) 24 - 25 - ## 1.0.0 26 - 27 - ### Major Changes 28 - 29 - - **Goodbye IE11!** 👋 This major release removes support for IE11. All code that is shipped will be transpiled much less and will _not_ be ES5-compatible anymore, by [@kitten](https://github.com/kitten) (See [#2504](https://github.com/FormidableLabs/urql/pull/2504)) 30 - - Upgrade to [Wonka v6](https://github.com/0no-co/wonka) (`wonka@^6.0.0`), which has no breaking changes but is built to target ES2015 and comes with other minor improvements. 31 - The library has fully been migrated to TypeScript which will hopefully help with making contributions easier!, by [@kitten](https://github.com/kitten) (See [#2504](https://github.com/FormidableLabs/urql/pull/2504)) 32 - 33 - ### Patch Changes 34 - 35 - - Updated dependencies (See [#2551](https://github.com/FormidableLabs/urql/pull/2551), [#2504](https://github.com/FormidableLabs/urql/pull/2504), [#2619](https://github.com/FormidableLabs/urql/pull/2619), [#2607](https://github.com/FormidableLabs/urql/pull/2607), and [#2504](https://github.com/FormidableLabs/urql/pull/2504)) 36 - - @urql/core@3.0.0 37 - 38 - ## 0.1.14 39 - 40 - ### Patch Changes 41 - 42 - - Extend peer dependency range of `graphql` to include `^16.0.0`. 43 - As always when upgrading across many packages of `urql`, especially including `@urql/core` we recommend you to deduplicate dependencies after upgrading, using `npm dedupe` or `npx yarn-deduplicate`, by [@kitten](https://github.com/kitten) (See [#2133](https://github.com/FormidableLabs/urql/pull/2133)) 44 - - Updated dependencies (See [#2133](https://github.com/FormidableLabs/urql/pull/2133)) 45 - - @urql/core@2.3.6 46 - 47 - ## 0.1.13 48 - 49 - ### Patch Changes 50 - 51 - - Bump extract-files package to 11.0.0, by [@haswalt](https://github.com/haswalt) (See [#1795](https://github.com/FormidableLabs/urql/pull/1795)) 52 - 53 - ## 0.1.12 54 - 55 - ### Patch Changes 56 - 57 - - Remove closure-compiler from the build step (See [#1570](https://github.com/FormidableLabs/urql/pull/1570)) 58 - - Updated dependencies (See [#1570](https://github.com/FormidableLabs/urql/pull/1570), [#1509](https://github.com/FormidableLabs/urql/pull/1509), [#1600](https://github.com/FormidableLabs/urql/pull/1600), and [#1515](https://github.com/FormidableLabs/urql/pull/1515)) 59 - - @urql/core@2.1.0 60 - 61 - ## 0.1.11 62 - 63 - ### Patch Changes 64 - 65 - - ⚠️ Fix the production build overwriting the development build. Specifically in the previous release we mistakenly replaced all development bundles with production bundles. This doesn't have any direct influence on how these packages work, but prevented development warnings from being logged or full errors from being thrown, by [@kitten](https://github.com/kitten) (See [#1097](https://github.com/FormidableLabs/urql/pull/1097)) 66 - - Updated dependencies (See [#1097](https://github.com/FormidableLabs/urql/pull/1097)) 67 - - @urql/core@1.14.1 68 - 69 - ## 0.1.10 70 - 71 - ### Patch Changes 72 - 73 - - Deprecate the `Operation.operationName` property in favor of `Operation.kind`. This name was 74 - previously confusing as `operationName` was effectively referring to two different things. You can 75 - safely upgrade to this new version, however to mute all deprecation warnings you will have to 76 - **upgrade** all `urql` packages you use. If you have custom exchanges that spread operations, please 77 - use [the new `makeOperation` helper 78 - function](https://formidable.com/open-source/urql/docs/api/core/#makeoperation) instead, by [@bkonkle](https://github.com/bkonkle) (See [#1045](https://github.com/FormidableLabs/urql/pull/1045)) 79 - - Updated dependencies (See [#1094](https://github.com/FormidableLabs/urql/pull/1094) and [#1045](https://github.com/FormidableLabs/urql/pull/1045)) 80 - - @urql/core@1.14.0 81 - 82 - ## 0.1.9 83 - 84 - ### Patch Changes 85 - 86 - - Omit the `Content-Type: application/json` HTTP header when using GET in the `fetchExchange`, `persistedFetchExchange`, or `multipartFetchExchange`, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#957](https://github.com/FormidableLabs/urql/pull/957)) 87 - - Updated dependencies (See [#947](https://github.com/FormidableLabs/urql/pull/947), [#962](https://github.com/FormidableLabs/urql/pull/962), and [#957](https://github.com/FormidableLabs/urql/pull/957)) 88 - - @urql/core@1.13.0 89 - 90 - ## 0.1.8 91 - 92 - ### Patch Changes 93 - 94 - - Upgrade to a minimum version of wonka@^4.0.14 to work around issues with React Native's minification builds, which use uglify-es and could lead to broken bundles, by [@kitten](https://github.com/kitten) (See [#842](https://github.com/FormidableLabs/urql/pull/842)) 95 - - Updated dependencies (See [#838](https://github.com/FormidableLabs/urql/pull/838) and [#842](https://github.com/FormidableLabs/urql/pull/842)) 96 - - @urql/core@1.12.0 97 - 98 - ## 0.1.7 99 - 100 - ### Patch Changes 101 - 102 - - Add `source` debug name to all `dispatchDebug` calls during build time to identify events by which exchange dispatched them, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#780](https://github.com/FormidableLabs/urql/pull/780)) 103 - - Updated dependencies (See [#780](https://github.com/FormidableLabs/urql/pull/780)) 104 - - @urql/core@1.11.7 105 - 106 - ## 0.1.6 107 - 108 - ### Patch Changes 109 - 110 - - Add a `"./package.json"` entry to the `package.json`'s `"exports"` field for Node 14. This seems to be required by packages like `rollup-plugin-svelte` to function properly, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#771](https://github.com/FormidableLabs/urql/pull/771)) 111 - - Updated dependencies (See [#771](https://github.com/FormidableLabs/urql/pull/771)) 112 - - @urql/core@1.11.6 113 - 114 - ## 0.1.5 115 - 116 - ### Patch Changes 117 - 118 - - Add debugging events to exchanges that add more detailed information on what is happening 119 - internally, which will be displayed by devtools like the urql [Chrome / Firefox extension](https://github.com/FormidableLabs/urql-devtools), by [@andyrichardson](https://github.com/andyrichardson) (See [#608](https://github.com/FormidableLabs/urql/pull/608)) 120 - - Add @urql/core/internal entrypoint for internally shared utilities and start sharing fetchExchange-related code, by [@kitten](https://github.com/kitten) (See [#722](https://github.com/FormidableLabs/urql/pull/722)) 121 - - Updated dependencies (See [#608](https://github.com/FormidableLabs/urql/pull/608), [#718](https://github.com/FormidableLabs/urql/pull/718), and [#722](https://github.com/FormidableLabs/urql/pull/722)) 122 - - @urql/core@1.11.0 123 - 124 - ## 0.1.4 125 - 126 - ### Patch Changes 127 - 128 - - Add graphql@^15.0.0 to peer dependency range, by [@kitten](https://github.com/kitten) (See [#688](https://github.com/FormidableLabs/urql/pull/688)) 129 - - Bump extract-files to ^8.1.0, by [@kitten](https://github.com/kitten) (See [#688](https://github.com/FormidableLabs/urql/pull/688)) 130 - - ⚠️ Fix non-2xx results never being parsed as GraphQL results. This can result in valid GraphQLErrors being hidden, which should take precedence over generic HTTP NetworkErrors, by [@kitten](https://github.com/kitten) (See [#678](https://github.com/FormidableLabs/urql/pull/678)) 131 - - Updated dependencies (See [#688](https://github.com/FormidableLabs/urql/pull/688) and [#678](https://github.com/FormidableLabs/urql/pull/678)) 132 - - @urql/core@1.10.8 133 - 134 - ## 0.1.3 135 - 136 - ### Patch Changes 137 - 138 - - ⚠️ Fix node resolution when using Webpack, which experiences a bug where it only resolves 139 - `package.json:main` instead of `module` when an `.mjs` file imports a package, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#642](https://github.com/FormidableLabs/urql/pull/642)) 140 - - Updated dependencies (See [#642](https://github.com/FormidableLabs/urql/pull/642)) 141 - - @urql/core@1.10.4 142 - 143 - ## 0.1.2 144 - 145 - ### Patch Changes 146 - 147 - - ⚠️ Fix multipart conversion, in the `extract-files` dependency (used by multipart-fetch) there is an explicit check for the constructor property of an object. This made the files unretrievable, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#639](https://github.com/FormidableLabs/urql/pull/639)) 148 - - ⚠️ Fix Node.js Module support for v13 (experimental-modules) and v14. If your bundler doesn't support 149 - `.mjs` files and fails to resolve the new version, please double check your configuration for 150 - Webpack, or similar tools, by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#637](https://github.com/FormidableLabs/urql/pull/637)) 151 - - Updated dependencies (See [#637](https://github.com/FormidableLabs/urql/pull/637)) 152 - - @urql/core@1.10.3 153 - 154 - ## 0.1.1 155 - 156 - ### Patch Changes 157 - 158 - - ⚠️ Fix Rollup bundle output being written to .es.js instead of .esm.js, by [@kitten](https://github.com/kitten) (See [#609](https://github.com/FormidableLabs/urql/pull/609)) 159 - - Updated dependencies (See [#609](https://github.com/FormidableLabs/urql/pull/609)) 160 - - @urql/core@1.10.1 161 - 162 - ## 0.1.0 163 - 164 - ### Initial release 165 - 166 - - Release the `multipartFetchExchange`
-34
exchanges/multipart-fetch/README.md
··· 1 - # @urql/exchange-multipart-fetch 2 - 3 - > **DEPRECATION NOTICE**: The `multipartFetchExchange` has been deprecated, and 4 - > `@urql/core` now supports GraphQL Multipart Requests natively. This won't 5 - > break the behaviour of your existing apps, however, it's recommended to remove 6 - > the `multipartFetchExchange` from your apps. 7 - 8 - The `multipartFetchExchange` is an exchange that builds on the regular `fetchExchange` 9 - but adds the multipart file upload capability. 10 - 11 - ## Quick Start Guide 12 - 13 - First install `@urql/exchange-multipart-fetch` alongside `urql`: 14 - 15 - ```sh 16 - yarn add @urql/exchange-multipart-fetch 17 - # or 18 - npm install --save @urql/exchange-multipart-fetch 19 - ``` 20 - 21 - You'll then need to add the `multipartFetchExchange` method, that this package exposes, 22 - to your `exchanges`. 23 - 24 - ```js 25 - import { createClient, dedupExchange, cacheExchange } from 'urql'; 26 - import { multipartFetchExchange } from '@urql/exchange-multipart-fetch'; 27 - 28 - const client = createClient({ 29 - url: 'http://localhost:1234/graphql', 30 - exchanges: [dedupExchange, cacheExchange, multipartFetchExchange], 31 - }); 32 - ``` 33 - 34 - Now we can start uploading files to our server!
-60
exchanges/multipart-fetch/package.json
··· 1 - { 2 - "name": "@urql/exchange-multipart-fetch", 3 - "version": "1.1.0", 4 - "description": "An exchange that allows regular fetch and will transition to multipart when files are included", 5 - "sideEffects": false, 6 - "homepage": "https://formidable.com/open-source/urql/docs/", 7 - "bugs": "https://github.com/urql-graphql/urql/issues", 8 - "license": "MIT", 9 - "repository": { 10 - "type": "git", 11 - "url": "https://github.com/urql-graphql/urql.git", 12 - "directory": "exchanges/multipart-fetch" 13 - }, 14 - "keywords": [ 15 - "urql", 16 - "graphql", 17 - "exchanges" 18 - ], 19 - "main": "dist/urql-exchange-multipart-fetch", 20 - "module": "dist/urql-exchange-multipart-fetch.mjs", 21 - "types": "dist/urql-exchange-multipart-fetch.d.ts", 22 - "source": "src/index.ts", 23 - "exports": { 24 - ".": { 25 - "import": "./dist/urql-exchange-multipart-fetch.mjs", 26 - "require": "./dist/urql-exchange-multipart-fetch.js", 27 - "types": "./dist/urql-exchange-multipart-fetch.d.ts", 28 - "source": "./src/index.ts" 29 - }, 30 - "./package.json": "./package.json" 31 - }, 32 - "files": [ 33 - "LICENSE", 34 - "CHANGELOG.md", 35 - "README.md", 36 - "dist/", 37 - "extras/" 38 - ], 39 - "scripts": { 40 - "test": "vitest --config ../../vitest.config.ts", 41 - "clean": "rimraf dist extras", 42 - "check": "tsc --noEmit", 43 - "lint": "eslint --ext=js,jsx,ts,tsx .", 44 - "build": "rollup -c ../../scripts/rollup/config.mjs", 45 - "prepare": "node ../../scripts/prepare/index.js", 46 - "prepublishOnly": "run-s clean build" 47 - }, 48 - "dependencies": { 49 - "@urql/core": ">=4.0.0", 50 - "extract-files": "^11.0.0", 51 - "wonka": "^6.3.0" 52 - }, 53 - "devDependencies": { 54 - "@urql/core": "workspace:*", 55 - "graphql": "^16.0.0" 56 - }, 57 - "publishConfig": { 58 - "access": "public" 59 - } 60 - }
-741
exchanges/multipart-fetch/src/__snapshots__/multipartFetchExchange.test.ts.snap
··· 1 - // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html 2 - 3 - exports[`on error > returns error data 1`] = ` 4 - { 5 - "data": undefined, 6 - "error": [CombinedError: [Network] No Content], 7 - "extensions": undefined, 8 - "hasNext": false, 9 - "operation": { 10 - "context": { 11 - "fetchOptions": { 12 - "method": "POST", 13 - }, 14 - "requestPolicy": "cache-first", 15 - "url": "http://localhost:3000/graphql", 16 - }, 17 - "key": 2, 18 - "kind": "query", 19 - "query": { 20 - "__key": -2395444236, 21 - "definitions": [ 22 - { 23 - "directives": [], 24 - "kind": "OperationDefinition", 25 - "name": { 26 - "kind": "Name", 27 - "value": "getUser", 28 - }, 29 - "operation": "query", 30 - "selectionSet": { 31 - "kind": "SelectionSet", 32 - "selections": [ 33 - { 34 - "alias": undefined, 35 - "arguments": [ 36 - { 37 - "kind": "Argument", 38 - "name": { 39 - "kind": "Name", 40 - "value": "name", 41 - }, 42 - "value": { 43 - "kind": "Variable", 44 - "name": { 45 - "kind": "Name", 46 - "value": "name", 47 - }, 48 - }, 49 - }, 50 - ], 51 - "directives": [], 52 - "kind": "Field", 53 - "name": { 54 - "kind": "Name", 55 - "value": "user", 56 - }, 57 - "selectionSet": { 58 - "kind": "SelectionSet", 59 - "selections": [ 60 - { 61 - "alias": undefined, 62 - "arguments": [], 63 - "directives": [], 64 - "kind": "Field", 65 - "name": { 66 - "kind": "Name", 67 - "value": "id", 68 - }, 69 - "selectionSet": undefined, 70 - }, 71 - { 72 - "alias": undefined, 73 - "arguments": [], 74 - "directives": [], 75 - "kind": "Field", 76 - "name": { 77 - "kind": "Name", 78 - "value": "firstName", 79 - }, 80 - "selectionSet": undefined, 81 - }, 82 - { 83 - "alias": undefined, 84 - "arguments": [], 85 - "directives": [], 86 - "kind": "Field", 87 - "name": { 88 - "kind": "Name", 89 - "value": "lastName", 90 - }, 91 - "selectionSet": undefined, 92 - }, 93 - ], 94 - }, 95 - }, 96 - ], 97 - }, 98 - "variableDefinitions": [ 99 - { 100 - "defaultValue": undefined, 101 - "directives": [], 102 - "kind": "VariableDefinition", 103 - "type": { 104 - "kind": "NamedType", 105 - "name": { 106 - "kind": "Name", 107 - "value": "String", 108 - }, 109 - }, 110 - "variable": { 111 - "kind": "Variable", 112 - "name": { 113 - "kind": "Name", 114 - "value": "name", 115 - }, 116 - }, 117 - }, 118 - ], 119 - }, 120 - ], 121 - "kind": "Document", 122 - "loc": { 123 - "end": 92, 124 - "source": { 125 - "body": "query getUser($name: String) { 126 - user(name: $name) { 127 - id 128 - firstName 129 - lastName 130 - } 131 - }", 132 - "locationOffset": { 133 - "column": 1, 134 - "line": 1, 135 - }, 136 - "name": "gql", 137 - }, 138 - "start": 0, 139 - }, 140 - }, 141 - "variables": { 142 - "name": "Clara", 143 - }, 144 - }, 145 - "stale": false, 146 - } 147 - `; 148 - 149 - exports[`on error > returns error data with status 400 and manual redirect mode 1`] = ` 150 - { 151 - "data": undefined, 152 - "error": [CombinedError: [Network] No Content], 153 - "extensions": undefined, 154 - "hasNext": false, 155 - "operation": { 156 - "context": { 157 - "fetchOptions": [MockFunction spy] { 158 - "calls": [ 159 - [], 160 - ], 161 - "results": [ 162 - { 163 - "type": "return", 164 - "value": { 165 - "redirect": "manual", 166 - }, 167 - }, 168 - ], 169 - }, 170 - "requestPolicy": "cache-first", 171 - "url": "http://localhost:3000/graphql", 172 - }, 173 - "key": 2, 174 - "kind": "query", 175 - "query": { 176 - "__key": -2395444236, 177 - "definitions": [ 178 - { 179 - "directives": [], 180 - "kind": "OperationDefinition", 181 - "name": { 182 - "kind": "Name", 183 - "value": "getUser", 184 - }, 185 - "operation": "query", 186 - "selectionSet": { 187 - "kind": "SelectionSet", 188 - "selections": [ 189 - { 190 - "alias": undefined, 191 - "arguments": [ 192 - { 193 - "kind": "Argument", 194 - "name": { 195 - "kind": "Name", 196 - "value": "name", 197 - }, 198 - "value": { 199 - "kind": "Variable", 200 - "name": { 201 - "kind": "Name", 202 - "value": "name", 203 - }, 204 - }, 205 - }, 206 - ], 207 - "directives": [], 208 - "kind": "Field", 209 - "name": { 210 - "kind": "Name", 211 - "value": "user", 212 - }, 213 - "selectionSet": { 214 - "kind": "SelectionSet", 215 - "selections": [ 216 - { 217 - "alias": undefined, 218 - "arguments": [], 219 - "directives": [], 220 - "kind": "Field", 221 - "name": { 222 - "kind": "Name", 223 - "value": "id", 224 - }, 225 - "selectionSet": undefined, 226 - }, 227 - { 228 - "alias": undefined, 229 - "arguments": [], 230 - "directives": [], 231 - "kind": "Field", 232 - "name": { 233 - "kind": "Name", 234 - "value": "firstName", 235 - }, 236 - "selectionSet": undefined, 237 - }, 238 - { 239 - "alias": undefined, 240 - "arguments": [], 241 - "directives": [], 242 - "kind": "Field", 243 - "name": { 244 - "kind": "Name", 245 - "value": "lastName", 246 - }, 247 - "selectionSet": undefined, 248 - }, 249 - ], 250 - }, 251 - }, 252 - ], 253 - }, 254 - "variableDefinitions": [ 255 - { 256 - "defaultValue": undefined, 257 - "directives": [], 258 - "kind": "VariableDefinition", 259 - "type": { 260 - "kind": "NamedType", 261 - "name": { 262 - "kind": "Name", 263 - "value": "String", 264 - }, 265 - }, 266 - "variable": { 267 - "kind": "Variable", 268 - "name": { 269 - "kind": "Name", 270 - "value": "name", 271 - }, 272 - }, 273 - }, 274 - ], 275 - }, 276 - ], 277 - "kind": "Document", 278 - "loc": { 279 - "end": 92, 280 - "source": { 281 - "body": "query getUser($name: String) { 282 - user(name: $name) { 283 - id 284 - firstName 285 - lastName 286 - } 287 - }", 288 - "locationOffset": { 289 - "column": 1, 290 - "line": 1, 291 - }, 292 - "name": "gql", 293 - }, 294 - "start": 0, 295 - }, 296 - }, 297 - "variables": { 298 - "name": "Clara", 299 - }, 300 - }, 301 - "stale": false, 302 - } 303 - `; 304 - 305 - exports[`on success > returns response data 1`] = ` 306 - { 307 - "data": { 308 - "data": { 309 - "user": 1200, 310 - }, 311 - }, 312 - "error": undefined, 313 - "extensions": undefined, 314 - "hasNext": false, 315 - "operation": { 316 - "context": { 317 - "fetchOptions": [MockFunction spy] { 318 - "calls": [ 319 - [], 320 - ], 321 - "results": [ 322 - { 323 - "type": "return", 324 - "value": {}, 325 - }, 326 - ], 327 - }, 328 - "requestPolicy": "cache-first", 329 - "url": "http://localhost:3000/graphql", 330 - }, 331 - "key": 2, 332 - "kind": "query", 333 - "query": { 334 - "__key": -2395444236, 335 - "definitions": [ 336 - { 337 - "directives": [], 338 - "kind": "OperationDefinition", 339 - "name": { 340 - "kind": "Name", 341 - "value": "getUser", 342 - }, 343 - "operation": "query", 344 - "selectionSet": { 345 - "kind": "SelectionSet", 346 - "selections": [ 347 - { 348 - "alias": undefined, 349 - "arguments": [ 350 - { 351 - "kind": "Argument", 352 - "name": { 353 - "kind": "Name", 354 - "value": "name", 355 - }, 356 - "value": { 357 - "kind": "Variable", 358 - "name": { 359 - "kind": "Name", 360 - "value": "name", 361 - }, 362 - }, 363 - }, 364 - ], 365 - "directives": [], 366 - "kind": "Field", 367 - "name": { 368 - "kind": "Name", 369 - "value": "user", 370 - }, 371 - "selectionSet": { 372 - "kind": "SelectionSet", 373 - "selections": [ 374 - { 375 - "alias": undefined, 376 - "arguments": [], 377 - "directives": [], 378 - "kind": "Field", 379 - "name": { 380 - "kind": "Name", 381 - "value": "id", 382 - }, 383 - "selectionSet": undefined, 384 - }, 385 - { 386 - "alias": undefined, 387 - "arguments": [], 388 - "directives": [], 389 - "kind": "Field", 390 - "name": { 391 - "kind": "Name", 392 - "value": "firstName", 393 - }, 394 - "selectionSet": undefined, 395 - }, 396 - { 397 - "alias": undefined, 398 - "arguments": [], 399 - "directives": [], 400 - "kind": "Field", 401 - "name": { 402 - "kind": "Name", 403 - "value": "lastName", 404 - }, 405 - "selectionSet": undefined, 406 - }, 407 - ], 408 - }, 409 - }, 410 - ], 411 - }, 412 - "variableDefinitions": [ 413 - { 414 - "defaultValue": undefined, 415 - "directives": [], 416 - "kind": "VariableDefinition", 417 - "type": { 418 - "kind": "NamedType", 419 - "name": { 420 - "kind": "Name", 421 - "value": "String", 422 - }, 423 - }, 424 - "variable": { 425 - "kind": "Variable", 426 - "name": { 427 - "kind": "Name", 428 - "value": "name", 429 - }, 430 - }, 431 - }, 432 - ], 433 - }, 434 - ], 435 - "kind": "Document", 436 - "loc": { 437 - "end": 92, 438 - "source": { 439 - "body": "query getUser($name: String) { 440 - user(name: $name) { 441 - id 442 - firstName 443 - lastName 444 - } 445 - }", 446 - "locationOffset": { 447 - "column": 1, 448 - "line": 1, 449 - }, 450 - "name": "gql", 451 - }, 452 - "start": 0, 453 - }, 454 - }, 455 - "variables": { 456 - "name": "Clara", 457 - }, 458 - }, 459 - "stale": false, 460 - } 461 - `; 462 - 463 - exports[`on success > returns response data 2`] = `"{\\"operationName\\":\\"getUser\\",\\"query\\":\\"query getUser($name: String) {\\\\n user(name: $name) {\\\\n id\\\\n firstName\\\\n lastName\\\\n }\\\\n}\\",\\"variables\\":{\\"name\\":\\"Clara\\"}}"`; 464 - 465 - exports[`on success > uses a file when given 1`] = ` 466 - { 467 - "data": { 468 - "data": { 469 - "user": 1200, 470 - }, 471 - }, 472 - "error": undefined, 473 - "extensions": undefined, 474 - "hasNext": false, 475 - "operation": { 476 - "context": { 477 - "fetchOptions": [MockFunction spy] { 478 - "calls": [ 479 - [], 480 - ], 481 - "results": [ 482 - { 483 - "type": "return", 484 - "value": {}, 485 - }, 486 - ], 487 - }, 488 - "requestPolicy": "cache-first", 489 - "url": "http://localhost:3000/graphql", 490 - }, 491 - "key": 3, 492 - "kind": "mutation", 493 - "query": { 494 - "__key": 8029062428, 495 - "definitions": [ 496 - { 497 - "directives": [], 498 - "kind": "OperationDefinition", 499 - "name": { 500 - "kind": "Name", 501 - "value": "uploadProfilePicture", 502 - }, 503 - "operation": "mutation", 504 - "selectionSet": { 505 - "kind": "SelectionSet", 506 - "selections": [ 507 - { 508 - "alias": undefined, 509 - "arguments": [ 510 - { 511 - "kind": "Argument", 512 - "name": { 513 - "kind": "Name", 514 - "value": "picture", 515 - }, 516 - "value": { 517 - "kind": "Variable", 518 - "name": { 519 - "kind": "Name", 520 - "value": "picture", 521 - }, 522 - }, 523 - }, 524 - ], 525 - "directives": [], 526 - "kind": "Field", 527 - "name": { 528 - "kind": "Name", 529 - "value": "uploadProfilePicture", 530 - }, 531 - "selectionSet": { 532 - "kind": "SelectionSet", 533 - "selections": [ 534 - { 535 - "alias": undefined, 536 - "arguments": [], 537 - "directives": [], 538 - "kind": "Field", 539 - "name": { 540 - "kind": "Name", 541 - "value": "location", 542 - }, 543 - "selectionSet": undefined, 544 - }, 545 - ], 546 - }, 547 - }, 548 - ], 549 - }, 550 - "variableDefinitions": [ 551 - { 552 - "defaultValue": undefined, 553 - "directives": [], 554 - "kind": "VariableDefinition", 555 - "type": { 556 - "kind": "NamedType", 557 - "name": { 558 - "kind": "Name", 559 - "value": "File", 560 - }, 561 - }, 562 - "variable": { 563 - "kind": "Variable", 564 - "name": { 565 - "kind": "Name", 566 - "value": "picture", 567 - }, 568 - }, 569 - }, 570 - ], 571 - }, 572 - ], 573 - "kind": "Document", 574 - "loc": { 575 - "end": 110, 576 - "source": { 577 - "body": "mutation uploadProfilePicture($picture: File) { 578 - uploadProfilePicture(picture: $picture) { 579 - location 580 - } 581 - }", 582 - "locationOffset": { 583 - "column": 1, 584 - "line": 1, 585 - }, 586 - "name": "gql", 587 - }, 588 - "start": 0, 589 - }, 590 - }, 591 - "variables": { 592 - "picture": File {}, 593 - }, 594 - }, 595 - "stale": false, 596 - } 597 - `; 598 - 599 - exports[`on success > uses a file when given 2`] = `FormData {}`; 600 - 601 - exports[`on success > uses multiple files when given 1`] = ` 602 - { 603 - "data": { 604 - "data": { 605 - "user": 1200, 606 - }, 607 - }, 608 - "error": undefined, 609 - "extensions": undefined, 610 - "hasNext": false, 611 - "operation": { 612 - "context": { 613 - "fetchOptions": [MockFunction spy] { 614 - "calls": [ 615 - [], 616 - ], 617 - "results": [ 618 - { 619 - "type": "return", 620 - "value": {}, 621 - }, 622 - ], 623 - }, 624 - "requestPolicy": "cache-first", 625 - "url": "http://localhost:3000/graphql", 626 - }, 627 - "key": 3, 628 - "kind": "mutation", 629 - "query": { 630 - "__key": -6039055341, 631 - "definitions": [ 632 - { 633 - "directives": [], 634 - "kind": "OperationDefinition", 635 - "name": { 636 - "kind": "Name", 637 - "value": "uploadProfilePictures", 638 - }, 639 - "operation": "mutation", 640 - "selectionSet": { 641 - "kind": "SelectionSet", 642 - "selections": [ 643 - { 644 - "alias": undefined, 645 - "arguments": [ 646 - { 647 - "kind": "Argument", 648 - "name": { 649 - "kind": "Name", 650 - "value": "pictures", 651 - }, 652 - "value": { 653 - "kind": "Variable", 654 - "name": { 655 - "kind": "Name", 656 - "value": "pictures", 657 - }, 658 - }, 659 - }, 660 - ], 661 - "directives": [], 662 - "kind": "Field", 663 - "name": { 664 - "kind": "Name", 665 - "value": "uploadProfilePicture", 666 - }, 667 - "selectionSet": { 668 - "kind": "SelectionSet", 669 - "selections": [ 670 - { 671 - "alias": undefined, 672 - "arguments": [], 673 - "directives": [], 674 - "kind": "Field", 675 - "name": { 676 - "kind": "Name", 677 - "value": "location", 678 - }, 679 - "selectionSet": undefined, 680 - }, 681 - ], 682 - }, 683 - }, 684 - ], 685 - }, 686 - "variableDefinitions": [ 687 - { 688 - "defaultValue": undefined, 689 - "directives": [], 690 - "kind": "VariableDefinition", 691 - "type": { 692 - "kind": "ListType", 693 - "type": { 694 - "kind": "NamedType", 695 - "name": { 696 - "kind": "Name", 697 - "value": "File", 698 - }, 699 - }, 700 - }, 701 - "variable": { 702 - "kind": "Variable", 703 - "name": { 704 - "kind": "Name", 705 - "value": "pictures", 706 - }, 707 - }, 708 - }, 709 - ], 710 - }, 711 - ], 712 - "kind": "Document", 713 - "loc": { 714 - "end": 116, 715 - "source": { 716 - "body": "mutation uploadProfilePictures($pictures: [File]) { 717 - uploadProfilePicture(pictures: $pictures) { 718 - location 719 - } 720 - }", 721 - "locationOffset": { 722 - "column": 1, 723 - "line": 1, 724 - }, 725 - "name": "gql", 726 - }, 727 - "start": 0, 728 - }, 729 - }, 730 - "variables": { 731 - "picture": [ 732 - File {}, 733 - File {}, 734 - ], 735 - }, 736 - }, 737 - "stale": false, 738 - } 739 - `; 740 - 741 - exports[`on success > uses multiple files when given 2`] = `FormData {}`;
-1
exchanges/multipart-fetch/src/index.ts
··· 1 - export * from './multipartFetchExchange';
-180
exchanges/multipart-fetch/src/multipartFetchExchange.test.ts
··· 1 - import { Client, OperationResult } from '@urql/core'; 2 - import { empty, fromValue, pipe, Source, toPromise } from 'wonka'; 3 - 4 - import { 5 - vi, 6 - expect, 7 - it, 8 - beforeEach, 9 - describe, 10 - beforeAll, 11 - Mock, 12 - afterEach, 13 - afterAll, 14 - } from 'vitest'; 15 - 16 - import { multipartFetchExchange } from './multipartFetchExchange'; 17 - 18 - import { 19 - uploadOperation, 20 - queryOperation, 21 - multipleUploadOperation, 22 - } from './test-utils'; 23 - 24 - const fetch = (global as any).fetch as Mock; 25 - const abort = vi.fn(); 26 - 27 - beforeAll(() => { 28 - (global as any).AbortController = function AbortController() { 29 - this.signal = undefined; 30 - this.abort = abort; 31 - }; 32 - }); 33 - 34 - afterEach(() => { 35 - fetch.mockClear(); 36 - abort.mockClear(); 37 - }); 38 - 39 - afterAll(() => { 40 - (global as any).AbortController = undefined; 41 - }); 42 - 43 - const response = JSON.stringify({ 44 - status: 200, 45 - data: { 46 - data: { 47 - user: 1200, 48 - }, 49 - }, 50 - }); 51 - 52 - const exchangeArgs = { 53 - forward: () => empty as Source<OperationResult>, 54 - client: {} as Client, 55 - dispatchDebug: vi.fn(), 56 - }; 57 - 58 - describe('on success', () => { 59 - beforeEach(() => { 60 - fetch.mockResolvedValue({ 61 - status: 200, 62 - headers: { get: () => 'application/json' }, 63 - text: vi.fn().mockResolvedValue(response), 64 - }); 65 - }); 66 - 67 - it('uses a file when given', async () => { 68 - const fetchOptions = vi.fn().mockReturnValue({}); 69 - 70 - const data = await pipe( 71 - fromValue({ 72 - ...uploadOperation, 73 - context: { 74 - ...uploadOperation.context, 75 - fetchOptions, 76 - }, 77 - }), 78 - multipartFetchExchange(exchangeArgs), 79 - toPromise 80 - ); 81 - 82 - expect(data).toMatchSnapshot(); 83 - expect(fetchOptions).toHaveBeenCalled(); 84 - expect(fetch.mock.calls[0][1].body).toMatchSnapshot(); 85 - }); 86 - 87 - it('uses multiple files when given', async () => { 88 - const fetchOptions = vi.fn().mockReturnValue({}); 89 - 90 - const data = await pipe( 91 - fromValue({ 92 - ...multipleUploadOperation, 93 - context: { 94 - ...multipleUploadOperation.context, 95 - fetchOptions, 96 - }, 97 - }), 98 - multipartFetchExchange(exchangeArgs), 99 - toPromise 100 - ); 101 - 102 - expect(data).toMatchSnapshot(); 103 - expect(fetchOptions).toHaveBeenCalled(); 104 - expect(fetch.mock.calls[0][1].body).toMatchSnapshot(); 105 - }); 106 - 107 - it('returns response data', async () => { 108 - const fetchOptions = vi.fn().mockReturnValue({}); 109 - 110 - const data = await pipe( 111 - fromValue({ 112 - ...queryOperation, 113 - context: { 114 - ...queryOperation.context, 115 - fetchOptions, 116 - }, 117 - }), 118 - multipartFetchExchange(exchangeArgs), 119 - toPromise 120 - ); 121 - 122 - expect(data).toMatchSnapshot(); 123 - expect(fetchOptions).toHaveBeenCalled(); 124 - expect(fetch.mock.calls[0][1].body).toMatchSnapshot(); 125 - }); 126 - }); 127 - 128 - describe('on error', () => { 129 - beforeEach(() => { 130 - fetch.mockResolvedValue({ 131 - status: 400, 132 - headers: { get: () => 'application/json' }, 133 - text: vi.fn().mockResolvedValue('{}'), 134 - }); 135 - }); 136 - 137 - it('returns error data', async () => { 138 - const data = await pipe( 139 - fromValue(queryOperation), 140 - multipartFetchExchange(exchangeArgs), 141 - toPromise 142 - ); 143 - 144 - expect(data).toMatchSnapshot(); 145 - }); 146 - 147 - it('returns error data with status 400 and manual redirect mode', async () => { 148 - const fetchOptions = vi.fn().mockReturnValue({ redirect: 'manual' }); 149 - 150 - const data = await pipe( 151 - fromValue({ 152 - ...queryOperation, 153 - context: { 154 - ...queryOperation.context, 155 - fetchOptions, 156 - }, 157 - }), 158 - multipartFetchExchange(exchangeArgs), 159 - toPromise 160 - ); 161 - 162 - expect(data).toMatchSnapshot(); 163 - }); 164 - 165 - it('ignores the error when a result is available', async () => { 166 - fetch.mockResolvedValue({ 167 - status: 400, 168 - headers: { get: () => 'application/json' }, 169 - text: vi.fn().mockResolvedValue(response), 170 - }); 171 - 172 - const data = await pipe( 173 - fromValue(queryOperation), 174 - multipartFetchExchange(exchangeArgs), 175 - toPromise 176 - ); 177 - 178 - expect(data.data).toEqual(JSON.parse(response).data); 179 - }); 180 - });
-110
exchanges/multipart-fetch/src/multipartFetchExchange.ts
··· 1 - import { filter, merge, mergeMap, pipe, takeUntil, onPush } from 'wonka'; 2 - import { extractFiles } from 'extract-files'; 3 - import { Exchange } from '@urql/core'; 4 - 5 - import { 6 - makeFetchBody, 7 - makeFetchURL, 8 - makeFetchOptions, 9 - makeFetchSource, 10 - } from '@urql/core/internal'; 11 - 12 - /** An Exchange which creates a multipart request when File/Blobs are found in variables. 13 - * @deprecated 14 - * `@urql/core` now supports the GraphQL Multipart Request spec out-of-the-box. 15 - */ 16 - export const multipartFetchExchange: Exchange = 17 - ({ forward, dispatchDebug }) => 18 - operations$ => { 19 - const fetchResults$ = pipe( 20 - operations$, 21 - filter(operation => { 22 - return operation.kind === 'query' || operation.kind === 'mutation'; 23 - }), 24 - mergeMap(operation => { 25 - const teardown$ = pipe( 26 - operations$, 27 - filter(op => op.kind === 'teardown' && op.key === operation.key) 28 - ); 29 - 30 - // Spreading operation.variables here in case someone made a variables with Object.create(null). 31 - const { files, clone: variables } = extractFiles({ 32 - ...operation.variables, 33 - }); 34 - const body = makeFetchBody({ query: operation.query, variables }); 35 - 36 - let url: string; 37 - let fetchOptions: RequestInit; 38 - if (files.size) { 39 - url = makeFetchURL(operation); 40 - fetchOptions = makeFetchOptions(operation); 41 - if (!(fetchOptions.body instanceof FormData)) { 42 - if (fetchOptions.headers!['content-type'] === 'application/json') { 43 - delete fetchOptions.headers!['content-type']; 44 - } 45 - 46 - fetchOptions.method = 'POST'; 47 - fetchOptions.body = new FormData(); 48 - fetchOptions.body.append('operations', JSON.stringify(body)); 49 - 50 - const map = {}; 51 - let i = 0; 52 - files.forEach(paths => { 53 - map[++i] = paths.map(path => `variables.${path}`); 54 - }); 55 - 56 - fetchOptions.body.append('map', JSON.stringify(map)); 57 - 58 - i = 0; 59 - files.forEach((_, file) => { 60 - (fetchOptions.body as FormData).append(`${++i}`, file, file.name); 61 - }); 62 - } 63 - } else { 64 - url = makeFetchURL(operation, body); 65 - fetchOptions = makeFetchOptions(operation, body); 66 - } 67 - 68 - dispatchDebug({ 69 - type: 'fetchRequest', 70 - message: 'A fetch request is being executed.', 71 - operation, 72 - data: { 73 - url, 74 - fetchOptions, 75 - }, 76 - }); 77 - 78 - return pipe( 79 - makeFetchSource(operation, url, fetchOptions), 80 - takeUntil(teardown$), 81 - onPush(result => { 82 - const error = !result.data ? result.error : undefined; 83 - 84 - dispatchDebug({ 85 - type: error ? 'fetchError' : 'fetchSuccess', 86 - message: `A ${ 87 - error ? 'failed' : 'successful' 88 - } fetch response has been returned.`, 89 - operation, 90 - data: { 91 - url, 92 - fetchOptions, 93 - value: error || result, 94 - }, 95 - }); 96 - }) 97 - ); 98 - }) 99 - ); 100 - 101 - const forward$ = pipe( 102 - operations$, 103 - filter(operation => { 104 - return operation.kind !== 'query' && operation.kind !== 'mutation'; 105 - }), 106 - forward 107 - ); 108 - 109 - return merge([fetchResults$, forward$]); 110 - };
-84
exchanges/multipart-fetch/src/test-utils.ts
··· 1 - import { 2 - gql, 3 - GraphQLRequest, 4 - OperationContext, 5 - Operation, 6 - makeOperation, 7 - } from '@urql/core'; 8 - 9 - const context: OperationContext = { 10 - fetchOptions: { 11 - method: 'POST', 12 - }, 13 - requestPolicy: 'cache-first', 14 - url: 'http://localhost:3000/graphql', 15 - }; 16 - 17 - const queryGql: GraphQLRequest = { 18 - key: 2, 19 - query: gql` 20 - query getUser($name: String) { 21 - user(name: $name) { 22 - id 23 - firstName 24 - lastName 25 - } 26 - } 27 - `, 28 - variables: { 29 - name: 'Clara', 30 - }, 31 - }; 32 - 33 - const obj = { hello: 'world' }; 34 - const file = new File( 35 - [new Blob([JSON.stringify(obj, null, 2)], { type: 'application/json' })], 36 - 'index.ts' 37 - ); 38 - const files = [file, file]; 39 - 40 - const upload: GraphQLRequest = { 41 - key: 3, 42 - query: gql` 43 - mutation uploadProfilePicture($picture: File) { 44 - uploadProfilePicture(picture: $picture) { 45 - location 46 - } 47 - } 48 - `, 49 - variables: { 50 - picture: file, 51 - }, 52 - }; 53 - 54 - const uploads: GraphQLRequest = { 55 - key: 3, 56 - query: gql` 57 - mutation uploadProfilePictures($pictures: [File]) { 58 - uploadProfilePicture(pictures: $pictures) { 59 - location 60 - } 61 - } 62 - `, 63 - variables: { 64 - picture: files, 65 - }, 66 - }; 67 - 68 - export const uploadOperation: Operation = makeOperation( 69 - 'mutation', 70 - upload, 71 - context 72 - ); 73 - 74 - export const multipleUploadOperation: Operation = makeOperation( 75 - 'mutation', 76 - uploads, 77 - context 78 - ); 79 - 80 - export const queryOperation: Operation = makeOperation( 81 - 'query', 82 - queryGql, 83 - context 84 - );
-4
exchanges/multipart-fetch/tsconfig.json
··· 1 - { 2 - "extends": "../../tsconfig.json", 3 - "include": ["src"] 4 - }