MichalLytek / MichalLytek/type-graphql
Error: Subscription field must return Async Iterable. Received: undefined.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the Bug**
Error after subscription client.
**To Reproduce**
```
/// server
import { ApolloServer } from 'apollo-server-express';
import express from 'express';
import { useServer } from 'graphql-ws/lib/use/ws';
import { createServer } from 'http';
import { WebSocketServer } from 'ws';
/// ...
const app = express();
const httpServer = createServer(app);
const wsServer = new WebSocketServer({
server: httpServer,
path: '/',
})
const schema = buildFederatedSchema({ orphanedTypes, resolvers, pubSub })
const serverCleanup = useServer({ schema }, wsServer);
const server = new ApolloServer({ schema });
await server.start();
server.applyMiddleware({ app, path: '/' });
httpServer.listen({ port }, ... );
/// resolver
import { withFilter } from 'graphql-subscriptions';
import {
Resolver,
Root,
Args,
Subscription,
} from 'type-graphql';
/// ...
@Resolver()
export class SubscriptionResolver {
@Subscription(() => Notification, {
subscribe: withFilter(
() => pubSub.asyncIterator(topics),
(root, args) => {
return args.type === root.type;
},
),
// subscribe() {
// return pubSub.asyncIterator(topics);
// },
// topics,
// topics: ({ args }) => args.type,
// filter: ({ args, payload }) => {
// return args.type === payload.type;
// },
})
notifications(@Root() payload: NotificationPayload, @Args() args: NotificationArgs) {
return {
type: args.typeNotify,
date: payload.date,
meta: payload?.meta,
};
}
```
**Expected Behavior**
After execution of subscription operation on Studio ApolloGraphql sandbox, i expect to connect to the socket, and receive messages on the emission of events. But get the error subscribe
**Logs**
```
...
🚀 Query endpoint ready at http://localhost:3008/
🚀 Subscriptions ready at ws://localhost:3008/
Internal error occurred during message handling. Please check your implementation. Error: Subscription field must return Async Iterable. Received: undefined.
at createSourceEventStream (/***/node_modules/graphql/execution/subscribe.js:165:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async subscribe (/***/node_modules/graphql/execution/subscribe.js:67:26)
at async onMessage (/***/node_modules/graphql-ws/lib/server.js:191:51)
at async WebSocket. (/***/node_modules/graphql-ws/lib/use/ws.js:83:21)
```
**Environment (please complete the following information):**
- Package version - v1.2.0-rc.1
- OS: MacOS Monteray
- Node - 16.17.0
- TypeScript version - 4.7.4
- npm - v1.2.0-rc.1
**Additional Context**
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the subscription with the shown ApolloServer, graphql-ws, and type-graphql resolver setup, then inspect graphql/execution/subscribe.js and graphql-ws/lib/server.js around the reported error. Compare the resolver's subscribe callback with the Async Iterable expected by GraphQL. Done means the subscription connects and receives emitted events without the undefined Async Iterable error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100