diff --git a/packages/graphql-fixtures/CHANGELOG.md b/packages/graphql-fixtures/CHANGELOG.md index bd41c99d8d..8773606ebd 100644 --- a/packages/graphql-fixtures/CHANGELOG.md +++ b/packages/graphql-fixtures/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 4.0.1 - 2022-12-07 + +### Changed + +- Removes calls to set faker seed if it's not needed [[#2701]](https://github.com/Shopify/quilt/pull/2701) + ## 4.0.0 ### Major Changes diff --git a/packages/graphql-fixtures/package.json b/packages/graphql-fixtures/package.json index 97ff1cd544..567b81cc67 100644 --- a/packages/graphql-fixtures/package.json +++ b/packages/graphql-fixtures/package.json @@ -1,6 +1,6 @@ { "name": "graphql-fixtures", - "version": "4.0.0", + "version": "4.0.1", "license": "MIT", "description": "Utilities for generating fixture objects from GraphQL documents.", "main": "index.js", diff --git a/packages/graphql-fixtures/src/fill.ts b/packages/graphql-fixtures/src/fill.ts index 844262a944..a579383918 100644 --- a/packages/graphql-fixtures/src/fill.ts +++ b/packages/graphql-fixtures/src/fill.ts @@ -379,6 +379,16 @@ function createValue( request: Request, details: ResolveDetails, ) { + // If the partial fill value is a primitive type, + // we can just return it directly and avoid reseeding the faker instance + if ( + typeof partialValue === 'string' || + typeof partialValue === 'boolean' || + typeof partialValue === 'number' + ) { + return partialValue; + } + return withRandom( request, details.parentFields, diff --git a/packages/graphql-fixtures/src/tests/fill.test.ts b/packages/graphql-fixtures/src/tests/fill.test.ts index dcc96c80d3..2512d92cab 100644 --- a/packages/graphql-fixtures/src/tests/fill.test.ts +++ b/packages/graphql-fixtures/src/tests/fill.test.ts @@ -22,6 +22,10 @@ describe('createFillers()', () => { chooseNull.mockReset(); }); + afterEach(() => { + jest.restoreAllMocks(); + }); + describe('fillOperation', () => { it('fills string fields', () => { const {fillOperation} = createFillerForSchema(` @@ -348,9 +352,27 @@ describe('createFillers()', () => { parents: [Person!]! } + enum CountryCode { + CA + US + GB + } + + enum CurrencyCode { + CAD + USD + GBP + } + + type LocalizationCollection { + countryCodes: [CountryCode!]! + currencyCodes: [CurrencyCode!]! + } + type Query { self: Person! sibling: Person + localizations: [LocalizationCollection!]! } `); @@ -426,6 +448,30 @@ describe('createFillers()', () => { data.self.parents[1].name, ); }); + + it('does not excessively seed the faker instance for prefilled data', () => { + const spy = jest.spyOn(faker, 'seed'); + + const document = createDocument<{ + self: {parents: {name: string}[]}; + }>(` + query SeedCheck { + localizations { + countryCodes + currencyCodes + } + } + `); + + const data = fillOperation(document, { + localizations: Array.from({length: 20}).map(() => ({ + countryCodes: Array.from({length: 250}).map(() => 'CA'), + currencyCodes: Array.from({length: 150}).map(() => 'CAD'), + })), + }); + + expect(spy.mock.calls.length).toBeLessThan(100); + }); }); describe('objects', () => {