facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

Schema extensions are ignored on MacOS, but not on Linux #4557

Open rbalicki2 opened 10 months ago

rbalicki2 commented 10 months ago

It looks like schema extensions are ignored on Mac, but not on Linux (x64). Is there a workaround?

Steps to reproduce

On Mac (platform: darwin, arch: arm64), this fails to compile, due to a missing field. On Linux (platform: linux, arch: x64), this successfully compiles.

The contents of the schema extension file can be arbitrary on Mac; it is never even parsed. However, it must exist.

Thank you!

rbalicki2 commented 10 months ago

Upon additional investigation, the issue is that on Mac, we create a Watchman query containing

                        DirName(
                            DirNameTerm {
                                path: "schema-extension.graphql",
                                depth: None,
                            },
                        ),

Changing this to schemaExtensions: [folderContainingExtension] is a workaround.

captbaritone commented 10 months ago

Thanks for the report and the followup. Should we be creating a different Watchman query here maybe? Or maybe just be more explicit (including validation) that we are expecting directories?

captbaritone commented 10 months ago

Looks like in the Rust code we are expecting directories here. Maybe we can add a runtime validation that ensures they are existing directories before creating the Watchman query?

https://github.com/facebook/relay/blob/1a57f08326653b0803a8ecb26894895e4e6e1556/compiler/crates/relay-compiler/src/config.rs#L694

rasck commented 9 months ago

We have been using relay for 2 years. Today i tried to install Watchman on my windows laptop to use the --watch flag and then relay-compiler doesn't work

image

This is our config file:

// relay.config.js
module.exports = {
  schema: 'schema.server.graphql',
  src: 'src',
  excludes: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
  noFutureProofEnums: true,
  language: 'typescript',
  customScalars: {},
  schemaExtensions: ['src/relay/schema.client.graphql'],
};

Our dev deps:

    "relay-compiler": "^13.2.0",
    "relay-compiler-language-typescript": "^15.0.1",
    "relay-config": "^12.0.1",

If i manually add the schema definitions in src/relay/schema.client.graphql in the end of our schema.server.graphql it works

tobias-tengler commented 9 months ago

I believe the schemaExtensions is supposed to point to a directory that contains *.graphql files with the extensions. At least that is what has worked for me...

sudame commented 8 months ago

I discovered that it functions correctly when both the schema file and the schemaExtensions files are placed in the same directory.

As demonstrated here (modified from @rbalicki2's demo project):

// <project-root>/schema/schema-extension.graphql is the local-schema-extension file
// <project-root>/schema/schema.graphql is the server-schema file

// relay.config.js
module.exports = {
  src: "./src",
  language: "typescript",
  schema: "./schema/schema.graphql",
  schemaExtensions: ["./schema"],
  excludes: ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"],
};

I'm not sure if this is the intended behavior or a bug.