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

Subscription types are incorrect #479

@affanshahid

Description

@affanshahid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions