Robert Schäfer cca7d78d25 refactor(backend): put fetch into context
It's a best practice to add HTTP API clients to the `context`. Standard Apollo GraphQL tutorial has an example:
https://www.apollographql.com/docs/apollo-server/data/context#resolvers

Also database drivers, loggers, message queues or process environment defined configuration should go into the `context`, just like HTTP-clients.
2025-06-19 00:41:42 +08:00

12 lines
373 B
TypeScript

import type { Context } from '@src/context'
import { mapboxResponses } from './mapboxResponses'
export const fetchMock: Context['fetch'] = (url) => {
const response: unknown = mapboxResponses[url] // eslint-disable-line security/detect-object-injection
if (!response) {
throw new Error(`Missing response for url: ${url}`)
}
return Promise.resolve(response)
}