Skip to content

Commit e1ca85e

Browse files
Fix a bug where the new operationType property wasn't passed into operation. (#12748)
Co-authored-by: Jerel Miller <[email protected]> Co-authored-by: jerelmiller <[email protected]>
1 parent 575bf3e commit e1ca85e

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

.changeset/fresh-swans-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Fix a bug where the new `operationType` property wasn't passed into `operation`.

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43643,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38635,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33333,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27618
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43723,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38671,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33349,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27607
66
}

src/core/__tests__/ApolloClient/links.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FormattedExecutionResult } from "graphql";
1+
import { type FormattedExecutionResult, OperationTypeNode } from "graphql";
22
import { gql } from "graphql-tag";
33
import type { Observable, Subscription } from "rxjs";
44
import { map, of } from "rxjs";
@@ -395,4 +395,50 @@ describe("Link interactions", () => {
395395

396396
expect(result.current!.query).toMatchDocument(expectedQuery);
397397
});
398+
399+
it("passes all expected properties into links", async () => {
400+
let operation!: Operation;
401+
const link = new ApolloLink((op) => {
402+
operation = op;
403+
return of({ data: { hello: "world" } });
404+
});
405+
const client = new ApolloClient({
406+
link,
407+
cache: new InMemoryCache(),
408+
});
409+
const query = gql`
410+
query HelloWorld {
411+
hello
412+
}
413+
`;
414+
await client
415+
.query({
416+
query,
417+
})
418+
.catch(() => {});
419+
expect(operation).toStrictEqualTyped({
420+
variables: {},
421+
extensions: {},
422+
operationName: "HelloWorld",
423+
operationType: OperationTypeNode.QUERY,
424+
query,
425+
});
426+
expect(Object.keys(operation)).toEqual([
427+
"variables",
428+
"extensions",
429+
"operationName",
430+
"operationType",
431+
"query",
432+
]);
433+
expect(Object.getOwnPropertyNames(operation)).toEqual([
434+
"variables",
435+
"extensions",
436+
"operationName",
437+
"operationType",
438+
"query",
439+
"setContext",
440+
"getContext",
441+
"client",
442+
]);
443+
});
398444
});

src/link/utils/transformOperation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function transformOperation(operation: GraphQLRequest): GraphQLRequest {
66
variables: operation.variables || {},
77
extensions: operation.extensions || {},
88
operationName: operation.operationName,
9+
operationType: operation.operationType,
910
query: operation.query,
1011
};
1112

0 commit comments

Comments
 (0)