Nexus: Typings are broken

Created on 6 Aug 2020  路  10Comments  路  Source: graphql-nexus/nexus

Types are broken in @nexus/schema/dist/definitions/subscriptionType.d.ts

Posting screenshot as it is easier to read
image

Posting text so google can find this issue when others expeirence the same

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> & { resolve: FieldResolver<"Subscription", FieldName>; }) | NexusOutputFieldConfig<"Subscription", FieldName>' is not assignable to type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.
              Property 'subscribe' is missing in type 'NexusOutputFieldConfig<"Subscription", FieldName> & { resolve: FieldResolver<"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.

node_modules/@nexus/schema/dist/definitions/subscriptionType.d.ts:37:5 - error TS2416: Property 'field' in type 'SubscriptionDefinitionBlock' is not assignable to the same property in base type 'ObjectDefinitionBlock<"Subscription">'.
  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> & { resolve: FieldResolver<"Subscription", FieldName>; }) | NexusOutputFieldConfig<"Subscription", FieldName>' is not assignable to type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.
          Property 'subscribe' is missing in type 'NexusOutputFieldConfig<"Subscription", FieldName> & { resolve: FieldResolver<"Subscription", FieldName>; }' but required in type 'SubscribeFieldConfig<"Subscription", FieldName, any>'.

37     field<FieldName extends string>(name: FieldName, fieldConfig: SubscribeFieldConfig<'Subscription', FieldName>): void;
       ~~~~~

  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.
scoptypes typbug

All 10 comments

I have the same issue

I can confirm that downgrading to @nexus/[email protected] fixes the isusue

@cyrus-za are you using subscriptionType nexus type builder?

Maybe this is due to changes we made in the MaybePromiseDeep?

Just hit this as well, looks to be due to the changes in https://github.com/graphql-nexus/schema/pull/462 - can reproduce by installing the latest @nexus/schema and "skipLibCheck": false.

I think might have been why I punted on adding a dedicated subscriptionType builder in the first place. It can't easily implement ObjectDefinitionBlock because this implements OutputDefinitionBlock which includes any of the JIT "plugin" fields added to the builder, which are going to have different config signatures.

I suppose you may be able to make this work by running both conditionals for the ScalarSubSpread and SubscribeFieldConfig through the ScalarOutSpread and FieldOutConfig with a ternary - that way the configs would be the same structurally for both class methods.

Sorry for the delay @jasonkuhrt but no I am not using subscriptionType

Thanks @cyrus-za for confirming. I'm less sure about what is going on then though.

@tgriesser Yeah didn't feel as simple as I expected once getting into it. Looks like we still have some work to do! We'll try to look into this soon, even more so if it's affecting non-subscription-type users.

On vacation, back next week. Chance we can start then but not sure.

Fixed by #564

Thanks for fixing @jasonkuhrt. I want to add that I have a prisma model that is called a Subscription (references a stripe subscription and was created long before the project even used gql or prisma). I am not sure if its related to this, but for some reason when theres a objectType({ name: 'Subscription' }) Graphql playground shows a gql subscriptions in the docs, despite no apollo subscriptions even turned on

@cyrus-za Interesting, sounds like an issue, feel free to create a new one!

Was this page helpful?
0 / 5 - 0 ratings