nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: FormidableLabs/urql
Pull request #96 (2018-06-28 19:01:03)

Maintain base headers, even if fetchOptions provided
In response to issue #86 


Patch:
diff --git a/src/modules/http-exchange.ts b/src/modules/http-exchange.ts
index 69f2f9a3..87d84b32 100644
--- a/src/modules/http-exchange.ts
+++ b/src/modules/http-exchange.ts
@@ -46,10 +46,13 @@ export const httpExchange = (): IExchange => operation => {
 
     fetch(url, {
       body,
-      headers: { 'Content-Type': 'application/json' },
       method: 'POST',
       signal: abortController.signal,
       ...fetchOptions,
+      headers: {
+        'Content-Type': 'application/json',
+        ...fetchOptions.headers,
+      },
     })
       .then(res => (response = res))
       .then(checkStatus(fetchOptions.redirect))


Test patch:
diff --git a/src/tests/modules/client.test.ts b/src/tests/modules/client.test.ts
index 0bca0fc1..6f2ff959 100644
--- a/src/tests/modules/client.test.ts
+++ b/src/tests/modules/client.test.ts
@@ -304,6 +304,39 @@ describe('Client', () => {
       });
     });
 
+    it('should spread default headers over returned fetch options', done => {
+      client = new Client({
+        fetchOptions: {
+          headers: { authorization: 'test' },
+        },
+        url: 'http://localhost:3000/graphql',
+      });
+
+      (global as any).fetch.mockReturnValue(
+        Promise.resolve({
+          json: () => ({ data: [{ id: 5 }] }),
+          status: 200,
+        })
+      );
+
+      client.executeQuery({ query: '' }).then(() => {
+        const body = JSON.stringify({ query: '' });
+        expect((global as any).fetch).toHaveBeenCalledWith(
+          'http://localhost:3000/graphql',
+          {
+            body,
+            headers: {
+              'Content-Type': 'application/json',
+              authorization: 'test',
+            },
+            method: 'POST',
+          }
+        );
+
+        done();
+      });
+    });
+
     it('should return "No Data" if data is not present', done => {
       client = new Client({
         url: 'http://localhost:3000/graphql',
Repository: FormidableLabs/urql
Pull request #399 (2019-08-21 10:17:35)

Prevent adding __typename to toplevel operations


Patch:
diff --git a/src/utils/typenames.ts b/src/utils/typenames.ts
index d4979b5b..6fde1d11 100755
--- a/src/utils/typenames.ts
+++ b/src/utils/typenames.ts
@@ -2,7 +2,7 @@ import {
   DocumentNode,
   FieldNode,
   InlineFragmentNode,
-  OperationDefinitionNode,
+  Kind,
   visit,
 } from 'graphql';
 
@@ -35,9 +35,7 @@ const collectTypes = (obj: EntityLike | EntityLike[], types: string[] = []) => {
 export const collectTypesFromResponse = (response: object) =>
   collectTypes(response as EntityLike).filter((v, i, a) => a.indexOf(v) === i);
 
-const formatNode = (
-  n: FieldNode | InlineFragmentNode | OperationDefinitionNode
-) => {
+const formatNode = (n: FieldNode | InlineFragmentNode) => {
   if (n.selectionSet === undefined) {
     return false;
   }
@@ -57,9 +55,9 @@ const formatNode = (
       selections: [
         ...n.selectionSet.selections,
         {
-          kind: 'Field',
+          kind: Kind.FIELD,
           name: {
-            kind: 'Name',
+            kind: Kind.NAME,
             value: '__typename',
           },
         },
@@ -72,5 +70,4 @@ export const formatDocument = (astNode: DocumentNode) =>
   visit(astNode, {
     Field: formatNode,
     InlineFragment: formatNode,
-    OperationDefinition: formatNode,
   });


Test patch:
diff --git a/src/utils/typenames.test.ts b/src/utils/typenames.test.ts
index aadf1403..48a10591 100755
--- a/src/utils/typenames.test.ts
+++ b/src/utils/typenames.test.ts
@@ -14,7 +14,6 @@ describe('formatTypeNames', () => {
           id
           __typename
         }
-        __typename
       }
       "
     `);
@@ -29,15 +28,15 @@ describe('formatTypeNames', () => {
       __typename
     }`)
     ).toMatchInlineSnapshot(`
-            "{
-              todos {
-                id
-                __typename
-              }
-              __typename
-            }
-            "
-        `);
+                  "{
+                    todos {
+                      id
+                      __typename
+                    }
+                    __typename
+                  }
+                  "
+            `);
   });
 });
Repository: FormidableLabs/urql
Pull request #438 (2019-09-27 12:44:34)

(feat) - add suspense flag to context


Patch:
diff --git a/src/client.ts b/src/client.ts
index b6e06ed3..41e2ce47 100755
--- a/src/client.ts
+++ b/src/client.ts
@@ -194,7 +194,8 @@ export class Client {
       onEnd<OperationResult>(() => this.onOperationEnd(operation))
     );
 
-    return this.suspense && operationName !== 'subscription'
+    return (operation.context.suspense || this.suspense) &&
+      operationName === 'query'
       ? toSuspenseSource(result$)
       : result$;
   }
@@ -212,6 +213,9 @@ export class Client {
     variables?: object,
     context?: Partial<OperationContext>
   ): PromisifiedSource<OperationResult> {
+    if (!context || typeof context.suspense !== 'boolean') {
+      context = { ...context, suspense: false };
+    }
     return withPromise<OperationResult>(
       this.executeQuery(createRequest(query, variables), context)
     );
diff --git a/src/types.ts b/src/types.ts
index 9e16dbf2..49b88b18 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -49,6 +49,7 @@ export interface OperationContext {
   url: string;
   pollInterval?: number;
   meta?: OperationDebugMeta;
+  suspense?: boolean;
 }
 
 /** A [query]{@link Query} or [mutation]{@link Mutation} with additional metadata for use during transmission. */


Test patch:
diff --git a/src/client.test.ts b/src/client.test.ts
index 3f79dcbd..775e0406 100755
--- a/src/client.test.ts
+++ b/src/client.test.ts
@@ -90,6 +90,7 @@ describe('promisified arguments', () => {
       requestPolicy: 'cache-and-network',
       fetchOptions: undefined,
       fetch: undefined,
+      suspense: false,
     });
     expect(queryResult).toHaveProperty('then');
   });