1

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:

  1. 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.
  2. Adding a setInterval to call faker.seed() every 5 minutes.
  3. Passing a faker instance to the mocks (and turning mocks into a function that takes "faker") and setting the mocks property to the result of the function, then calling faker.seed() the same way as 1 and 2 above.
  4. Using casual instead of faker-js, but I get the same result.

Any help here would be greatly appreciated!

elrobe
  • 555
  • 2
  • 16

0 Answers0