UNPKG

@envelop/rate-limiter

Version:

This plugins uses [`graphql-rate-limit`](https://github.com/teamplanes/graphql-rate-limit#readme) in order to limit the rate of calling queries and mutations.

24 lines (23 loc) 773 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InMemoryStore = void 0; class InMemoryStore { // The store is mutable. // tslint:disable-next-line readonly-keyword state = {}; setForIdentity(identity, timestamps) { // tslint:disable-next-line no-object-mutation this.state = { ...this.state, [identity.contextIdentity]: { ...this.state[identity.contextIdentity], [identity.fieldIdentity]: [...timestamps], }, }; } getForIdentity(identity) { const ctxState = this.state[identity.contextIdentity]; return (ctxState && ctxState[identity.fieldIdentity]) || []; } } exports.InMemoryStore = InMemoryStore;