Skip to content

The same fragment yields a different hash value...? #4226

@kmin-283

Description

@kmin-283

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

Screenshot 2023-02-20 at 4 44 26 PM

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions