Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Flufd opened this issue Jun 17, 2022 · 1 comment · May be fixed by #2312
Open

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

Flufd opened this issue Jun 17, 2022 · 1 comment · May be fixed by #2312

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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants