Skip to content

info.cacheControl.cacheHint can only be set in globalMddleware, not resolver-based middleware. #199

Closed
@laukaichung

Description

@laukaichung

Describe the bug
This CacheControl middleware from #75 no longer works when I use it in individual resolvers:

import {MiddlewareFn} from "type-graphql";

export function CacheControl(maxAge:number = 60): MiddlewareFn {
    return ({info:{cacheControl}}, next) => {
        cacheControl.setCacheHint({maxAge})
        return next();

    };
}

The only working way is to call info.setCacheHint in global middlewares, which is not very ideal :

@Service()
export class ErrorLoggerMiddleware implements MiddlewareInterface<GqlContext> {
    async use({ context, info }: ResolverData<GqlContext>, next: NextFn) {
        cacheControl.setCacheHint({maxAge:60})
        ........
    }
}


let schema = await buildSchema({
        resolvers,
        validate: true,
        dateScalarMode: "isoDate",
        globalMiddlewares: [ErrorLoggerMiddleware],
});


I guess the info object from global middlewares is overriding the one from the resolver-based middlewares?

Enviorment (please complete the following information):

  • OS: Arch Linux
  • Node: 10.7.0
  • Package version : 0.15.0
  • TypeScript version : 3.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions