Right now I'm using apollo-server-express
and creating my ApolloServer with mocks
like so:
import { faker } from "@faker-js/faker";
export const mocks = {
Person: () => ({
name: faker.name.fullName
}),
People: () => ({
person: () => [...Array(faker.datatype.number({ min: 1, max: 5 }))]
})
}
Then initializing the server:
const server = new ApolloServer({
...
mocks,
mockEntireSchema: false,
...
});
Problem is, whenever I query my server (e.g. Query { people { person { name }}}
), I get the same list every time until I reboot my server. It's like rebooting the server is the only way to create a new seed.
Things I've tried:
- Adding a plugin that calls
faker.seed()
whenever a response is received. This does seem to set a seed, but the mocks don't seem to respect it. - Adding a setInterval to call
faker.seed()
every 5 minutes. - Passing a
faker
instance to themocks
(and turning mocks into a function that takes "faker") and setting the mocks property to the result of the function, then callingfaker.seed()
the same way as 1 and 2 above. - Using
casual
instead offaker-js
, but I get the same result.
Any help here would be greatly appreciated!