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.

support Headers being passed in fetchOptions

+41 -3
+5
.changeset/fluffy-poets-protect.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Correctly support the `Headers` class being used in `fetchOptions`
+24
packages/core/src/internal/fetchOptions.test.ts
··· 107 107 `); 108 108 }); 109 109 110 + it('handles the Headers object', () => { 111 + const headers = new Headers(); 112 + headers.append('x-test', 'true'); 113 + const operation = makeOperation(queryOperation.kind, queryOperation, { 114 + ...queryOperation.context, 115 + fetchOptions: { 116 + headers, 117 + }, 118 + }); 119 + const body = makeFetchBody(operation); 120 + 121 + expect(makeFetchOptions(operation, body)).toMatchInlineSnapshot(` 122 + { 123 + "body": "{\\"operationName\\":\\"getUser\\",\\"query\\":\\"query getUser($name: String) {\\\\n user(name: $name) {\\\\n id\\\\n firstName\\\\n lastName\\\\n }\\\\n}\\",\\"variables\\":{\\"name\\":\\"Clara\\"}}", 124 + "headers": { 125 + "accept": "application/graphql-response+json, application/graphql+json, application/json, text/event-stream, multipart/mixed", 126 + "content-type": "application/json", 127 + "x-test": "true", 128 + }, 129 + "method": "POST", 130 + } 131 + `); 132 + }); 133 + 110 134 it('creates a GET request when preferred for query operations', () => { 111 135 const operation = makeOperation(queryOperation.kind, queryOperation, { 112 136 ...queryOperation.context,
+12 -3
packages/core/src/internal/fetchOptions.ts
··· 129 129 (typeof operation.context.fetchOptions === 'function' 130 130 ? operation.context.fetchOptions() 131 131 : operation.context.fetchOptions) || {}; 132 - if (extraOptions.headers) 133 - for (const key in extraOptions.headers) 134 - headers[key.toLowerCase()] = extraOptions.headers[key]; 132 + if (extraOptions.headers) { 133 + if (extraOptions.headers.forEach) { 134 + (extraOptions.headers as Headers).forEach((value, key) => { 135 + headers[key] = value; 136 + }); 137 + } else { 138 + for (const key in extraOptions.headers) { 139 + headers[key.toLowerCase()] = extraOptions.headers[key]; 140 + } 141 + } 142 + } 143 + 135 144 const serializedBody = serializeBody(operation, body); 136 145 if (typeof serializedBody === 'string' && !headers['content-type']) 137 146 headers['content-type'] = 'application/json';