Skip to content

Commit cba0e69

Browse files
committed
test replacing params and result
1 parent 63929b1 commit cba0e69

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/core/test/perform.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,54 @@ describe('perform', () => {
139139
}
140140
`);
141141
});
142+
143+
it('should replace params in onPerform plugin', async () => {
144+
const getEnveloped = envelop({
145+
...graphqlFuncs,
146+
plugins: [
147+
useSchema(schema),
148+
{
149+
onPerform: ({ setParams }) => {
150+
setParams({ query: '{ hello }' });
151+
},
152+
},
153+
],
154+
});
155+
156+
const { perform } = getEnveloped();
157+
const result = await perform({ query: 'subscribe { greetings }' });
158+
assertSingleExecutionValue(result);
159+
160+
expect(result).toMatchInlineSnapshot(`
161+
Object {
162+
"data": Object {
163+
"hello": "world",
164+
},
165+
}
166+
`);
167+
});
168+
169+
it('should replace result in onPerformDone plugin', async () => {
170+
const replacedResult = { data: { something: 'else' } };
171+
172+
const getEnveloped = envelop({
173+
...graphqlFuncs,
174+
plugins: [
175+
useSchema(schema),
176+
{
177+
onPerform: () => ({
178+
onPerformDone: ({ setResult }) => {
179+
setResult(replacedResult);
180+
},
181+
}),
182+
},
183+
],
184+
});
185+
186+
const { perform } = getEnveloped();
187+
const result = await perform({ query: '{ hello }' });
188+
assertSingleExecutionValue(result);
189+
190+
expect(result).toBe(replacedResult);
191+
});
142192
});

0 commit comments

Comments
 (0)