graphql-framework-experiment icon indicating copy to clipboard operation
graphql-framework-experiment copied to clipboard

subscription type throws build error

Open paniavula opened this issue 4 years ago • 0 comments

The latest 0.26.1 throws back errors on build when subscriptionType is used. Sample subscription snippet is below.

import { schema } from 'nexus'
import { PubSub } from 'graphql-subscriptions'

const pubsub = new PubSub()

schema.subscriptionType({
  definition(t) {
    t.field('notif', {
      type: 'Json',
      subscribe(root, args, ctx, info) {
        return pubsub.asyncIterator('notification')
      },
      resolve(event, args, ctx, info) {
        return { a: 10 }
      },
    })
  },
})

Repro

  1. npx nexus@next
  2. Add above snippet to any of your code file
  3. npm run build -- throws the below error
 758 ● nexus:build get used plugins
● nexus:plugin:nexusPluginPrisma Running generators
● nexus:build starting reflection
● nexus:build building typescript program
● nexus:build compiling a production build
node_modules/@nexus/schema/dist/definitions/subscriptionType.d.ts:31:9 - error TS2416: Property 'list' in type 'SubscriptionDefinitionBlock' is not assignable to the same property in base type 'ObjectDefinitionBlock<"Subscription">'.
  Type 'SubscriptionDefinitionBlock' is not assignable to type 'OutputDefinitionBlock<"Subscription">'.
    Types of property 'field' are incompatible.
      Type '<FieldName extends string>(name: FieldName, fieldConfig: SubscribeFieldConfig<"Subscription", FieldName, any>) => void' is not assignable to type '<FieldName extends string>(name: FieldName, fieldConfig: FieldOutConfig<"Subscription", FieldName>) => void'.
        Types of parameters 'fieldConfig' and 'fieldConfig' are incompatible.
          Type 'FieldOutConfig<"Subscription", FieldName>' is not assignable to type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.
            Type 'NexusOutputFieldConfig<"Subscription", FieldName> | (NexusOutputFieldConfig<"Subscription", FieldName> & { ...; })' is not assignable to type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.
              Property 'subscribe' is missing in type 'NexusOutputFieldConfig<"Subscription", FieldName>' but required in type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.

31     get list(): SubscriptionDefinitionBlock;
           ~~~~

  node_modules/@nexus/schema/dist/definitions/subscriptionType.d.ts:23:5
    23     subscribe(root: object, args: ArgsValue<TypeName, FieldName>, ctx: GetGen<'context'>, info: GraphQLResolveInfo): MaybePromise<AsyncIterator<T>> | MaybePromiseDeep<AsyncIterator<T>>;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'subscribe' is declared here.

paniavula avatar Aug 05 '20 01:08 paniavula