relay icon indicating copy to clipboard operation
relay copied to clipboard

Schema extensions are ignored on MacOS, but not on Linux

Open rbalicki2 opened this issue 6 months ago • 6 comments

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

Steps to reproduce

  • Clone https://github.com/rbalicki2/relay-test
  • yarn && yarn relay

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 avatar Dec 20 '23 17:12 rbalicki2

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.

rbalicki2 avatar Dec 20 '23 18:12 rbalicki2

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 avatar Jan 10 '24 18:01 captbaritone

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

captbaritone avatar Jan 10 '24 18:01 captbaritone

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

rasck avatar Jan 31 '24 12:01 rasck

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...

tobias-tengler avatar Jan 31 '24 14:01 tobias-tengler

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.

sudame avatar Feb 23 '24 03:02 sudame