graphql-middleware icon indicating copy to clipboard operation
graphql-middleware copied to clipboard

Question: adding middleware around a (mock) type resolver?

Open jrnail23 opened this issue 4 years ago • 1 comments

I've been able to successfully apply middleware for fields, but when I try to apply one to a type resolver, it only applies the middleware to that type's field resolvers, not the type resolver itself. Is there a way to only have it apply to the type resolver? For example, given the below resolvers, I'd like to wrap the Contact type resolver, but I can only seem to get it to apply to that type's fields (e.g, name below).

// RESOLVERS
{
  // mock type resolver
  Contact: () => {
    return {
      name: () => { /* field resolver */ }
    }
  },
  Query: () => {
    contacts: () => { /* field resolver */ }
  }
}
// MIDDLEWARE
applyMiddleware(schema, {
  Contact: myMiddleware()
})

jrnail23 avatar May 30 '20 01:05 jrnail23

Hi @jrnail23 👋 ,

Could you explain in a bit more detail what a type-resolver would do? Maybe you could do some mocking by checking the name of the field? You can get that information from the info argument in the middleware.

maticzav avatar May 23 '21 06:05 maticzav