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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust compiler: definition of 'XYZQuery' appears to have changed #3437

Closed
Tracked by #3180
mrtnzlml opened this issue Apr 1, 2021 · 6 comments
Closed
Tracked by #3180

Rust compiler: definition of 'XYZQuery' appears to have changed #3437

mrtnzlml opened this issue Apr 1, 2021 · 6 comments

Comments

@mrtnzlml
Copy link
Contributor

mrtnzlml commented Apr 1, 2021

Hello! 馃憢 I am trying the new Relay Rust compiler and I managed to convert all artifacts successfully. However, I am getting the following errors in runtime:

The definition of 'XYZQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data.

It works fine with the "old" compiler so I guess there is some kind of incompatibility. Is it a bug? Is there something I am missing? Thanks for having a look!

My config:

{
  "root": "..",
  "sources": {
    "ya-comiste-backoffice/src": "default"
  },
  "codegenCommand": "yarn workspace @adeira/ya-comiste-backoffice relay",
  "projects": {
    "default": {
      "schema": "ya-comiste-rust/schema.graphql",
      "jsModuleFormat": "commonjs",
      "haste": false,
      "customScalarTypes": {
        "ProductImageUploadable": "String"
      }
    }
  },
  "isDevVariableName": "__DEV__"
}

Executing like this: relay-compiler-experimental ./relay.config.json

You can see all the changes in this PR: adeira/universe#2116

@kassens
Copy link
Member

kassens commented Apr 2, 2021

What happens is:

  • the compiler produces a hash at compile time
  • the babel plugin (when a DEV variable is set) produces a bit of code instead of just a require() statement that also contains a hash.

The hash used to be md5(graphql.print(graphql.parse(text))) and in the Rust compiler we just updated it to md5(text) to avoid needing 100% replication of graphql-js printing.

I thought we also made that change to the OSS babel plugin, but I guess we never migrated OSS? I need to double check this when I'm back at my work computer.

@mrtnzlml
Copy link
Contributor Author

mrtnzlml commented Apr 2, 2021

I thought we also made that change to the OSS babel plugin, but I guess we never migrated OSS? I need to double check this when I'm back at my work computer.

Thanks for having a look @kassens, much appreciated!

@kassens
Copy link
Member

kassens commented Apr 30, 2021

Moving comments from the wrong thread: #3438 (comment)

from @kassens

@mrtnzlml : Actually, I was wrong:
Rust also does md5(print(definition)) here:

source_hashes.insert(name, md5(&print_executable_definition_ast(ast)));

which should match this code

const hash = crypto
.createHash('md5')
.update(print(graphqlDefinition), 'utf8')
.digest('hex');

Maybe you have an example fragment where the output is different? Is it console.erroring for all definitions or a few exceptions? I could see that happen when you have escaped characters in strings or something uncommon maybe? That would be a bug internally as well though.

from @mrtnzlml

Hi @kassens! First and foremost, I verified whether this issue still exists in the latest version, and seems like yes. You can see the migration from "old" Relay Compiler to the "new" Relay Rust Compiler in this PR: adeira/universe#2119

Here are all the files I saw that changed their hash from the previous version:

src/abacus-backoffice/src/products/__generated__/CreateProductFormMutation.graphql.js
src/abacus-backoffice/src/products/__generated__/EditProductFormMutation.graphql.js
src/abacus-backoffice/src/products/__generated__/ProductsCardsQuery.graphql.js
src/abacus-backoffice/src/products/__generated__/ProductsEditLayoutQuery.graphql.js
src/kochka.com.mx/src/shop/__generated__/ProductPageLayoutQuery.graphql.js
src/kochka.com.mx/src/shop/__generated__/ShopLayoutContentQuery.graphql.js

I am having a hard time figuring out what could be the problem though. For example, check src/abacus-backoffice/src/products/__generated__/ProductsCardsQuery.graphql.js which results from the following query:

query ProductsCardsQuery {
  commerce {
    products: searchAllProducts(clientLocale: en_US, priceSortDirection: LOW_TO_HIGH) {
      id
      key
      name
      imageCover {
        blurhash
        url
      }
      price {
        unitAmount
        unitAmountCurrency
      }
    }
  }
}

Doesn't look suspicious. 馃 Do you have any idea what could it be?

Is it console.erroring for all definitions or a few exceptions?

A few exceptions listed above in the whole PR (adeira/universe#2119).

Thanks for having a look!

@kassens
Copy link
Member

kassens commented Apr 30, 2021

So it turns out graphql@15.4 and up changed the whitespace when printing definitions.

I used this little script to check the way it's printed and hashed (input is the input with the exact formatting that produces the hash in your PR)

import { parse, print } from "graphql";
import crypto from "crypto";

function md5(str) {
    return crypto
        .createHash('md5')
        .update(str, 'utf8')
        .digest('hex');
}

const input = "query ProductsCardsQuery {\n  commerce {\n    products: searchAllProducts(\n      clientLocale: en_US\n      priceSortDirection: LOW_TO_HIGH\n    ) {\n      id\n      key\n      name\n      imageCover {\n        blurhash\n        url\n      }\n      price {\n        unitAmount\n        unitAmountCurrency\n      }\n    }\n  }\n}";
const reprinted = print(parse(input).definitions[0]);

console.log(md5(input));
console.log(md5(reprinted));

I suspect the best solution is to pin the graphql dependency of babel-plugin-relay to graphql@15.3.

@alunyov
Copy link
Contributor

alunyov commented Nov 8, 2021

Added a PR for this: #3628

@bartonyoung
Copy link

bartonyoung commented Oct 26, 2023

Hello @alunyov @kassens my team is finally attempting to upgrade our complier but we are running to the same issue described above. There are no changes to the query definitions, but I still get the warning. Running the compiler properly generates the artifacts and our app functions as expected other than the console error.

I am running v16 on all required packages.

Our simple configuration looks like:

// relay.config.js
module.exports = {
  src: './src',
  schema: './schema.graphql',
  language: 'javascript',
  exclude: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
};

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

Successfully merging a pull request may close this issue.

4 participants