Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolver doesn't work with subscription #38

Open
josephktcheung opened this issue Sep 10, 2018 · 1 comment · May be fixed by #39
Open

Resolver doesn't work with subscription #38

josephktcheung opened this issue Sep 10, 2018 · 1 comment · May be fixed by #39

Comments

@josephktcheung
Copy link
Contributor

josephktcheung commented Sep 10, 2018

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

  1. 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;
}
  1. 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');
    }
}
  1. 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)
});
  1. Add test field to Message.graphql
type Message {
    id: Int
    text: String
    receiver: Int
    test: String
}
  1. Subscribe to messageSent with new test field:
subscription {
  messageSent(me: 1) {
    id
    text
    test
  }
}
  1. Create a new message
mutation {
  messageSave(id: 1, receiver: 1, text: "Hi") {
    id
    text
    test
  }
}
  1. 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)
@josephktcheung josephktcheung linked a pull request Sep 10, 2018 that will close this issue
@ghost
Copy link

ghost commented Dec 14, 2018

  • 1 this is making vesper unusable for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant