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

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

Open
rbalicki2 opened this issue Dec 20, 2023 · 8 comments
Open

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

rbalicki2 opened this issue Dec 20, 2023 · 8 comments

Comments

@rbalicki2
Copy link
Contributor

rbalicki2 commented Dec 20, 2023

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
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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?

/// List of directories with schema extensions.

@rasck
Copy link

rasck commented Jan 31, 2024

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
Copy link
Contributor

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
Copy link

sudame commented Feb 23, 2024

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.

@sverrejoh
Copy link
Contributor

In the Relay documentation the schemaExtensions is defined to be a folder:

This file needs to be in a folder referenced in the "schemaExtensions" of your Relay config.

Watchman will return the contents of the schemaExtension folder, and nothing if it is a file. The problem is Relay will fall back to manually walking the directory tree when watchman isn't available (Either because it isn't installed, or if disabled with the FORCE_NO_WATCHMAN=1 flag), and this codepath will include the schema extension even if it's a file.

@captbaritone Is there any reason schemaExtensions shouldn't be allowed to point to a file, or can we just fix the watchman expression and update the documentation to allow it?

@sverrejoh
Copy link
Contributor

sverrejoh commented Dec 3, 2024

I created a PR to allow schemaExtensions to be either a file path or a directory, by expanding the Watchman query here: #4859

This already worked when using the walkdir implementation (when watchman is disabled or not available). I also notice that in the Relay tests the fixtures uses schemaExtenstions that points directly to the graphql files (and it works because the tests uses the file walker implementation, not Watchman).

It's interesting now how the Schema can be defined explicitly as either schemaDir to point at a containing folder, or schema to point directly to a file, while schemaExtensions will support both using the same key, but I'm thinking as the functionality is already there (just partly and undocumented) this is fine.

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

No branches or pull requests

6 participants