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

Subscription - Property 'Subscription' is incompatible with index signature. #372

Closed
Chabane opened this issue Aug 1, 2017 · 2 comments
Closed

Comments

@Chabane
Copy link

Chabane commented Aug 1, 2017

Hello,

I got this error when I tried to execute this code. Do you have any idea?

src/index.ts(40,49): error TS2345: Argument of type '{ typeDefs: string; resolvers: { Query: { addCell: (: any, { type }: { type: any; }) => Prom...' is not assignable to parameter of type 'IExecutableSchemaDefinition'.
Types of property 'resolvers' are incompatible.
Type '{ Query: { addCell: (: any, { type }: { type: any; }) => Promise; }; Subscription: ...' is not assignable to type 'IResolvers'.
Property 'Subscription' is incompatible with index signature.
Type '{ newCell: { subscribe: (: any, { type }: { type: any; }) => AsyncIterator<{}>; }; }' is not assignable to type 'GraphQLScalarType | IResolverObject | (() => any)'.
Type '{ newCell: { subscribe: (: any, { type }: { type: any; }) => AsyncIterator<{}>; }; }' is not assignable to type '() => any'.
Type '{ newCell: { subscribe: (_: any, { type }: { type: any; }) => AsyncIterator<{}>; }; }' provides no match for the signature '(): any'.

import { PubSub } from 'graphql-subscriptions';
import { makeExecutableSchema } from 'graphql-tools';

const pubsub = new PubSub();

export const typeDefs = `

type Subscription {
  newCell: Cell
}

type Query {
  addCell(type: CellType!): Cell
}
[..]
schema {
  query: Query
  subscription: Subscription
}
`;

export const resolvers = {
  Query: {
    addCell: async (_, { type }) => {
      let cell = new Cell();
      cell.type = type;
      pubsub.publish('newCell', { newCell: cell });
      return cell;
    },
  },

  Subscription: {
    newCell: {
      subscribe: () =>
        pubsub.asyncIterator('newCell')
    }
  }
};

 let executableSchema = makeExecutableSchema({
      typeDefs,
      resolvers,
    });

The issue is related to the "subscribe" attribute.

Thanks

blazarus added a commit to blazarus/graphql-tools that referenced this issue Aug 3, 2017
This fixes issue ardatan#372. It seems like the 'subscribe' property was simply missing from the interface definition.
stubailo pushed a commit that referenced this issue Aug 15, 2017
This fixes issue #372. It seems like the 'subscribe' property was simply missing from the interface definition.
@lostpebble
Copy link

I'm getting a similar error:

export const resolvers: IResolvers = {
  Query: {
    hello: () => {
      return `Hello world`;
    },
    allLinks: () => {
      return [{
        id: "what",
        url: "dudewheresmycar.com",
        description: "Lekker bois.",
      }, {
        id: "numbertwo",
        url: "independence.com",
        description: "No man.",
      }];
    }
  },
  Subscription: {
    taskProgress: {
      subscribe: withFilter(() => pubsub.asyncIterator("taskProgress"), (payload, variables) => {
        return payload.taskId === variables.taskId;
      }),
    },
  },
};
TSError: ⨯ Unable to compile TypeScript
src\graphql\resolvers.ts (5,14): Type '{ Query: { hello: () => string; allLinks: () => { id: string; url: string; description: string; }...' is not assignable to type 'IResolvers'.
  Property 'Subscription' is incompatible with index signature.
    Type '{ taskProgress: { subscribe: Function; }; }' is not assignable to type '(() => any) | IResolverObject | GraphQLScalarType'.
      Type '{ taskProgress: { subscribe: Function; }; }' is not assignable to type 'GraphQLScalarType'.
        Property 'name' is missing in type '{ taskProgress: { subscribe: Function; }; }'. (2322)

It seems that the types are not working properly. As it's seeing taskProgress over there as a GraphQLScalarType instead of an IResolverObject.

I managed to make the above work by forcing it to see it as an IResolverObject, like so:

Subscription: {
    taskProgress: {
      subscribe: withFilter(() => pubsub.asyncIterator("taskProgress"), (payload, variables) => {
        return payload.taskId === variables.taskId;
      }),
    } as IResolverObject,
  },

@stubailo
Copy link
Contributor

I like the idea of rolling these up into a single issue about improving TypeScript definitions and compatibility. Let's do that in #704

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

No branches or pull requests

3 participants