Skip to content

Commit 02fff0e

Browse files
cheapsteaktrevor-scheer
authored andcommitted
Add test for handling subscriptions resolvers
1 parent 2bcb1cc commit 02fff0e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

packages/apollo-tools/src/__tests__/buildServiceDefinition.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,44 @@ type MutationRoot {
390390

391391
expect(nameField.resolve).toEqual(name);
392392
});
393+
394+
it(`should handle subscriptions`, () => {
395+
const commentAddedSubscription = () =>
396+
async function*() {
397+
yield "111";
398+
yield "222";
399+
yield "333";
400+
};
401+
402+
const service = buildServiceDefinition([
403+
{
404+
typeDefs: gql`
405+
type Subscription {
406+
commentAdded: String
407+
}
408+
`,
409+
resolvers: {
410+
Subscription: {
411+
commentAdded: {
412+
subscribe: commentAddedSubscription
413+
}
414+
}
415+
}
416+
}
417+
]);
418+
419+
expect(service.schema).toBeDefined();
420+
const schema = service.schema!;
421+
422+
const subscriptionType = schema.getType("Subscription");
423+
expect(subscriptionType).toBeDefined();
424+
425+
const commentAdded = (subscriptionType! as GraphQLObjectType).getFields()[
426+
"commentAdded"
427+
];
428+
expect(commentAdded).toBeDefined();
429+
430+
expect(commentAdded.subscribe).toEqual(commentAddedSubscription);
431+
});
393432
});
394433
});

0 commit comments

Comments
 (0)