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

inline graphql-js' printer #4692

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

cometkim
Copy link

@cometkim cometkim commented May 4, 2024

See #3628 and #4226

@captbaritone
Copy link
Contributor

This seems sensible to me. Feel free to ping me when this diff is ready for review (I see it's still marked as Draft).

@captbaritone
Copy link
Contributor

I wonder if there's a sensible way to add some tests which assert that the compiler and this code arrive at the same hash?

@cometkim
Copy link
Author

cometkim commented May 8, 2024

That's is easy if we can run the printer standalone. Or, it would be ideal to publish to NPM and directly use its WASM or NAPI distribution

@cometkim
Copy link
Author

Workaround: Commit md5 hashes for all the fixtures in the graphql-text-printer crate test suite. Then we can compare it when running the babel plugin tests.

@cometkim cometkim force-pushed the js-printer branch 3 times, most recently from 8df33f3 to cd480da Compare May 13, 2024 18:15
@cometkim
Copy link
Author

@captbaritone I added idempotency testing using compiler-side fixtures. Fixed 4 failures related to spaces between multiple definitions and it all passes.

@cometkim cometkim marked this pull request as ready for review May 13, 2024 18:21
return fixtures;
}

function parsePrintFixture(name: string, content: string): PrinterFixture {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this. Brilliant solution. When I merge I think I'll add a note in the Rust tests so that people know the fixtures are serving double duty.

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

cometkim added a commit to cometkim/vite-plugin-relay-lite that referenced this pull request May 14, 2024
* formatting rules.
*/
function print(ast: any): string {
return visit(ast, { leave: printDocASTReducer });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something weird here. By version 16.8.1 which we are supposed to be using, this had changed and there wasn't a top-level leave here anymore, each child visitor had a leave key.

I think there's some weird Yarn issues, becuase if I run yarn in this directory, I get a local node_modules directory with [email protected] which causes this to fail with many failures that look like this:

  ● printGraphQL › tests printer idempotence: conditions.expected

    TypeError: visitFn.call is not a function

      19 |  */
      20 | function print(ast: any): string {
    > 21 |   return visit(ast, { leave: printDocASTReducer });
         |                             ^
      22 | }
      23 |
      24 | const printDocASTReducer: any = {

      at Object.visit (packages/babel-plugin-relay/node_modules/graphql/language/visitor.js:197:15)
      at print (packages/babel-plugin-relay/printGraphQL.js:21:29)
      at packages/babel-plugin-relay/__tests__/printGraphQL-test.js:27:38

I think our test runner does not perform that yarn install for some reason. I'm honestly not even sure why this package has its own yarn.lock.

Copy link
Contributor

@captbaritone captbaritone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to land this internally due to the issue with yarn.lock (see my inline comment).

Do you mind looking into it? Maybe you can do some git blaming to figure out why we even have that yarn.lock in the first place?

@cometkim
Copy link
Author

cometkim commented Jun 7, 2024

I think it makes more sense for each package to have a lockfile since there is no workspaces setup, or gitignoring. yarn install is needed to run the test suite for react-relay, but it doesn't seem to be running anywhere?

Anyway, I'd suggest clearing it and activating the workspaces, it would improve your CI cache hits a lot.

@captbaritone
Copy link
Contributor

@cometkim Yeah, I could have sworn we had a workspace setup. Here's where we do the global yarn install. I guess we'll need to either setup the workspace or manually run install for this package.

https://github.com/facebook/relay/blob/main/.github/workflows/ci.yml#L45

@cometkim
Copy link
Author

cometkim commented Jun 7, 2024

setup here? or another pr?

@captbaritone
Copy link
Contributor

captbaritone commented Jun 7, 2024

Either way. Whatever you prefer.

@cometkim
Copy link
Author

cometkim commented Jun 8, 2024

#4711

I'm not sure it could actually boost the CI, let's see.

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

Successfully merging this pull request may close these issues.

3 participants