Custom typing GlobalContext

Not sure if you found an answer. GlobalContext is a Redwood-defined type. When you use the declare module syntax to define an ambient module, you’re replacing what’s already defined. I think you could import the type and extend your custom type (with the ipAddress key) from it, something like:

import type { GlobalContext as RWGlobalContext } from "@redwoodjs/graphql-server"

declare module '@redwoodjs/graphql-server' {
  interface GlobalContext extends RWGlobalContext {
    ipAddress?: string
  }
}

I didn’t test it to see if it works.

1 Like