typescript-mock-data generate 30 elements in a specific list

45 Views Asked by At

I have a NextJS app with Jest as the testing library. I'm trying to use typescript-mock-data to generate mock data from my apollo schema types in order to test against mocked data. In my codegen file i've tried this to get a specific field in a type to contain 30 elements:

  plugins: [
    {
      'typescript-mock-data': {
        typesFile: 'generated/schema/types.ts',
        typeNames: 'keep',
        terminateCircularRelationships: true,
        addTypename: true,
        fieldGeneration: {
          SearchResult: {
            products: {
              listElementCount: 30,
            },
          },
        },
      },
    },
  ],

this gives me an empty products list. But if i move listElementCount: 30 to the outer object like this:

  'typescript-mock-data': {
    typesFile: 'generated/schema/types.ts',
    typeNames: 'keep',
    terminateCircularRelationships: true,
    addTypename: true,
    listElementCount: 30,
    },

it works, but doesn't this mean that all lists in the whole mock is getting 30 elements? I only want SearchResult.products to have 30 elements. Is this possible to achieve? In the docs it doesn't say anything about selecting a specific field to generate the element count https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-mock-data

0

There are 0 best solutions below