Skip to content

Global Context type #1853

Answered by bombillazo
bombillazo asked this question in Q&A
Sep 13, 2021 · 3 comments · 10 replies
Discussion options

You must be logged in to vote

Ok got it to work the following manner:

  1. Add the declare statement in your code (as specified above). I have mine in the index.ts file where I create my graphql-modules application.
declare global {
  namespace GraphQLModules {
    interface GlobalContext {
      myProp: string; 
    }
  }
}  

const application = createApplication({
...
  1. Use GraphQL Code Generator typescript-resolvers plugin to add the context type to my resolvers. I am doing it programmatically but it's the same concept:
generates:
path/to/file.ts:
  plugins: 
    - typescript
    - typescript-resolvers
  config:
    contextType: "GraphQLModules.Context"
...

After that my resolver context gets typed! :D

Replies: 3 comments 10 replies

Comment options

You must be logged in to vote
2 replies
@bombillazo
Comment options

@bombillazo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@bombillazo
Comment options

@Urigo
Comment options

@bombillazo
Comment options

@Urigo
Comment options

@enheit
Comment options

Answer selected by bombillazo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants