Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

[graphql-fixtures] Seed collision for nested arrays on fill #2311

Open
Flufd opened this issue Jun 17, 2022 · 1 comment
Open

[graphql-fixtures] Seed collision for nested arrays on fill #2311

Flufd opened this issue Jun 17, 2022 · 1 comment

Comments

@Flufd
Copy link
Contributor

Flufd commented Jun 17, 2022

Overview

When using the graphQL filler to generate data with nested arrays, a faker seed collision occurs when generating the data for the elements in the arrays.

This is because the seedFromKeypath generates a seed from the keypath of the node that is being filled, based on the collective sum of all of the characters that make up that keypath.

Example:
Given this schema:

type Pet {
  id: ID!
}

type Person {
  pets: [Pet]!
}

type Query {
  people: [Person!]!
}

If we have two people with two pets each, the pets at person[0].pet[1] and person[1].pet[0] have the same seed generated, because their "sum" of the chars in the keypath is the same. Because of this, their IDs are the same.

Failing test here:
https://github.com/Shopify/quilt/compare/graphql-fixtures/seed-collision

This becomes a problematic issue when combined with the Apollo cache. By default, Apollo will normalise the items based on their id fields and so we get a cache collision and the test data we receive in a call to the Apollo client does not match the data we passed to the createGraphQLFactory result.

Potentially we could use some other stable method for generating the seed based on the keypath. Maybe some quick hash of the string? https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0

@BPScott
Copy link
Member

BPScott commented Jun 23, 2022

This crops up with a single entity too, you don't even need nesting for this to fail. These key paths will result in the same seed: person[12] and person[21] (and thus the 12th and 21st person will be the same)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants