Subscription fails if a field is resolved by a resolver.
Reproduction Steps
demo code available at https://github.com/josephktcheung/vesper/tree/feature/resolver_subscription, run sample 11 with npx ts-node sample/typescript/sample11-subscribers/index.ts
- Add a new
test field for Message
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Message {
@PrimaryGeneratedColumn()
id: number;
@Column()
text: string;
@Column()
receiver: number;
test: string;
}
- Add a resolver for the new field.
import { Resolve, Resolver, ResolverInterface } from "../../../../src";
import { EntityManager } from "typeorm";
import { Message } from "../entity/Message";
@Resolver(Message)
export class MessageResolver implements ResolverInterface<Message> {
constructor(private entityManager: EntityManager) {
}
@Resolve()
async test(messages: Message[]) {
return messages.map(m => 'test');
}
}
- Include resolver in
bootstrap:
import { bootstrap } from "../../../src";
import { MessageController } from "./controller/MessageController";
import { Message } from "./entity/Message";
import { PubSub } from "graphql-subscriptions";
import { MessageResolver } from "./resolver/MessageResolver";
const pubSub = new PubSub();
bootstrap({
port: 3000,
controllers: [MessageController],
resolvers: [MessageResolver],
entities: [Message],
schemas: [__dirname + "/schema/**/*.graphql"],
setupContainer: container => container.set(PubSub, pubSub),
subscriptionAsyncIterator: triggers => pubSub.asyncIterator(triggers)
});
- Add
test field to Message.graphql
type Message {
id: Int
text: String
receiver: Int
test: String
}
- Subscribe to
messageSent with new test field:
subscription {
messageSent(me: 1) {
id
text
test
}
}
- Create a new message
mutation {
messageSave(id: 1, receiver: 1, text: "Hi") {
id
text
test
}
}
- Following error appears in console:
TypeError: Cannot read property 'Message' of undefined
at resolvers.(anonymous function).(anonymous function) (/Users/josephcheung/workspace/zeep/repos/vesper/src/SchemaBuilder.ts:374:45)
at /Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql-tools/src/schemaGenerator.ts:683:22
at resolveFieldValueOrError (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:531:18)
at resolveField (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:495:16)
at /Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:364:18
at Array.reduce (<anonymous>)
at executeFields (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:361:42)
at collectAndExecuteSubfields (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:772:10)
at completeObjectValue (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:762:10)
at completeValue (/Users/josephcheung/workspace/zeep/repos/vesper/node_modules/graphql/execution/execute.js:660:12)
Subscription fails if a field is resolved by a resolver.
Reproduction Steps
demo code available at https://github.com/josephktcheung/vesper/tree/feature/resolver_subscription, run sample 11 with
npx ts-node sample/typescript/sample11-subscribers/index.tstestfield forMessagebootstrap:testfield toMessage.graphqlmessageSentwith newtestfield: