mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
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.
12 lines
373 B
TypeScript
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)
|
|
}
|