Skip to content

Commit 8122017

Browse files
committed
Add test to check @catch without to arg
1 parent 27eae0b commit 8122017

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/cache/inmemory/__tests__/cache.diff/catch.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,55 @@ test("returns FieldResult failure for a field with @catch(to: RESULT) when the f
9494
});
9595
});
9696

97+
test("defaults bare @catch to RESULT and does not inherit @catchByDefault", () => {
98+
const cache = new InMemoryCache();
99+
const query = gql`
100+
query UserQuery @catchByDefault(to: THROW) {
101+
user {
102+
id
103+
name @catch
104+
}
105+
}
106+
`;
107+
108+
cache.writeQuery({
109+
query,
110+
data: {
111+
user: {
112+
__typename: "User",
113+
id: "1",
114+
name: null,
115+
},
116+
},
117+
errors: [
118+
{
119+
message: "Cannot resolve user.name",
120+
path: ["user", "name"],
121+
},
122+
],
123+
});
124+
125+
expect(cache.diff({ query, optimistic: false })).toStrictEqualTyped({
126+
result: {
127+
user: {
128+
__typename: "User",
129+
id: "1",
130+
name: {
131+
ok: false,
132+
errors: [
133+
{
134+
message: "Cannot resolve user.name",
135+
path: ["user", "name"],
136+
},
137+
],
138+
},
139+
},
140+
},
141+
complete: true,
142+
missing: undefined,
143+
});
144+
});
145+
97146
test("throws for a field with @catch(to: THROW) when the field has a path error", () => {
98147
const cache = new InMemoryCache();
99148
const query = gql`

0 commit comments

Comments
 (0)