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.

15 lines (14 loc) 512 B
export const getNoOpCache = () => ({ set: ({ newTimestamps }) => newTimestamps, }); export const getWeakMapCache = () => { const cache = new WeakMap(); return { set: ({ context, fieldIdentity, newTimestamps, }) => { const currentCalls = cache.get(context) || {}; currentCalls[fieldIdentity] = [...(currentCalls[fieldIdentity] || []), ...newTimestamps]; cache.set(context, currentCalls); return currentCalls[fieldIdentity]; }, }; };