2

Is there a standard way of adding type bindings to a graphql resolver mapping?

sampleResolver.ts:

export default {
  sampleResolver: (parent, args, context, info) => {
    ...
    return ...
  }
};

e.g.

sampleResolver<...>: (parent, args, context, info) => ...

or

sampleResolver: (parent, args, context, info): ... => ...

or

sampleResolver: (parent: ..., args: ..., context:..., info:...) => ...

enter image description here

3
  • (As in Apollo's / graphql-tools's resolver map?) Commented Dec 15, 2019 at 2:53
  • Are you using Express along with Apollo GrapHQL? Commented Dec 15, 2019 at 17:48
  • @KingDarBoja, yes I am using apollo-server-express. Commented Dec 15, 2019 at 20:48

2 Answers 2

2
+50

I don't think apollo-server-express has implemented type definitions for resolvers as seen on this issue. However, you could try graphql-code-generator to automatically generate type definitions for you schemas, resolvers and so on.

Sign up to request clarification or add additional context in comments.

Comments

0

There are multiple ways to do that, see more. In your case i think this would be suitable:

sampleResolver.ts:

// Interface checking for return
export interface SampleResolver {
  [name: string]: any
}

// Then assign Interface at return
export default {
  sampleResolver: (parent, args, context, info) => {
    ...
    return <SampleResolver>...
  }
};

Note: The export is used for type checking in other files.

otherFiles.ts

import { SampleResolver } from 'sampleResolver';


var response: SampleResolver;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.