Skip to content
This repository was archived by the owner on May 10, 2018. It is now read-only.
This repository was archived by the owner on May 10, 2018. It is now read-only.

Using binding-ts for defining resolvers #72

Description

@danielkcz

I am not entirely sure what is the use case for binding-ts generator. I assume it's not meant to add type safety to resolvers? Either way, if I would like to make another generator for this case, would you accept PR for it or should it go as a standalone module? Unfortunately, it would be a lot of copy & paste.


Let me explain what issues there are for that generator to be used for resolvers properly. Besides regular types, enums, inputs ... which are correctly generated, there is this type.

export type Mutation = {
  authPlayer: (args: { input?: AuthPlayerInput }, context: { [key: string]: any }, info?: GraphQLResolveInfo | string) => Promise<AuthPlayer>
}

I cannot figure out how I would use that for typing my resolver. Also, there is an issue of a missing first argument being parent object.

Instead, I've figured out that this approach might serve much better.

export namespace Mutation {
  export authPlayer: (parent: any, args: { input?: AuthPlayerInput }, context: { [key: string]: any }, info?: GraphQLResolveInfo | string) => Promise<AuthPlayer>
}

const authPlayer: Mutation.authPlayer = async (_, { input }, ctx: Context) => {
   // nice type checking even for a return value
}

Looking at the code it shouldn't be that hard to do required tweaks, but it will be a lot of copy&paste which I am not for fond of :) Opinions?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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