The same fragment yields a different hash value...?
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
### fragment
```
fragment SellingProductListFragmentContainer_store_representActiveProducts on Store
@argumentDefinitions(
count: { type: "Int", defaultValue: 10 }
cursor: { type: "ID" }
filter: { type: "ProductFilter", defaultValue: { statuses: [ACTIVE], representStatus: ACTIVE } }
)
@refetchable(queryName: "SellingProductListFragmentContatinerRepresentActiveProducts") {
representActiveProducts: products(first: $count, after: $cursor, filter: $filter)
@connection(key: "SellingProductListFragmentContainer_store_representActiveProducts") {
edges {
node {
_id
}
}
}
}
```
When the relay-compiler command is executed, generated the hash value is

This result is presumably due to this code working.
https://github.com/facebook/relay/blob/c0cc17a07e1f0c01f3e5c564eed50b5a30f4228f/compiler/crates/relay-compiler/src/build_project/build_ir.rs
but when i execute same fragment in this code it return different hash value
```
const { parse, print } = require('graphql')
const crypto = require('node:crypto')
const gql = String.raw
const text = gql`
fragment SellingProductListFragmentContainer_store_representActiveProducts on Store
@argumentDefinitions(
count: { type: "Int", defaultValue: 10 }
cursor: { type: "ID" }
filter: { type: "ProductFilter", defaultValue: { statuses: [ACTIVE], representStatus: ACTIVE } }
)
@refetchable(queryName: "SellingProductListFragmentContatinerRepresentActiveProducts") {
representActiveProducts: products(first: $count, after: $cursor, filter: $filter)
@connection(key: "SellingProductListFragmentContainer_store_representActiveProducts") {
edges {
node {
_id
}
}
}
}
`
const ast = parse(text)
const definition = ast.definitions[0]
const printed = print(definition)
const hash = crypto.createHash('md5').update(printed, 'utf8').digest('hex')
console.log(hash)
```
the hash value is
```
296c46ae6772194c8404c631edebccbf
```
I put the same input into the md5 hash function, but why are the results different?
Contributor guide
Research direction
Start by reproducing the reported hashes from the fragment and JavaScript parse/print example. Read compiler/crates/relay-compiler/src/build_project/build_ir.rs and compare the compiler's input to graphql's printed definition. Done means explaining the differing inputs or hash process and documenting or fixing the discrepancy, with a regression test if the compiler behavior is changed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript, rust
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100