Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Subscription types are incorrect #479

Open
affanshahid opened this issue May 25, 2019 · 0 comments
Open

Subscription types are incorrect #479

affanshahid opened this issue May 25, 2019 · 0 comments

Comments

@affanshahid
Copy link

affanshahid commented May 25, 2019

Given a schema:

type Subscription {
  status(acdEngineId: Int!): JobStatus!
}

type JobStatus {
  jobStatus: String!
}

and types:

export interface JobStatus {
  jobStatus: string;
}

The generated subscription types looks like this:

export interface Type {
    status: {
      subscribe: (
        parent: undefined,
        args: JobStatus,
        ctx: Context,
        info: GraphQLResolveInfo
      ) => AsyncIterator<JobStatus> | Promise<AsyncIterator<JobStatus>>;
      ...
    };
  }

Which implies that we need an AsyncIterator that yields objects of type JobStatus, that is to say:

{
   jobStatus: 'something'
}

But when I use a custom written AsyncIterator to achieve this, I get errors saying jobStatus cannot be null. What I actually need to yield is the whole data payload:

{
   status: {
      jobStatus: 'something'
   }
}

Is this a bug or am I doing something wrong?

EDIT:
I feel this is also apparent in graphql-yoga examples, we need to return the entire payload i.e:
https://github.com/prisma/graphql-yoga/tree/master/examples/subscriptions

type Counter {
   count: Int!
   countStr: String
}

type Subscription {
    counter: Counter!
}
pubsub.publish(channel, { counter: { count: count++ } })

instead of just

pubsub.publish(channel, { count: count++ })

Versions

graphqlgen: 0.6.0-rc9
OS: Windows 10

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

No branches or pull requests

1 participant