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

Not finding local schema extensions #3986

Open rokn opened 2 years ago

rokn commented 2 years ago

Hey, I've tried adding a local client schema extension as described here: https://relay.dev/docs/guides/client-schema-extensions/

The problem arises when I try to compile a query which uses this extensions. I've set-up a tiny example repo which showcases the problem: https://github.com/rokn/relay-example-local-schema/

There is one schema in data/schema.graphql

And one extension schema in src/clientSchema.graphql

When I try to run the relay compiler I get the following error:

yarn run relay-compiler
yarn run v1.22.18
$ /home/rokn/relay-local-test/node_modules/.bin/relay-compiler
[INFO] querying files to compile...
[INFO] [default] compiling...
[ERROR] Error in the project `default`: ✖︎ The type `Query` has no field `notifications`.

  src/App.tsx:12:9
   11 │         }
   12 │         notifications {
      │         ^^^^^^^^^^^^^
   13 │             title

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
 - Validation errors:
 - The type `Query` has no field `notifications`.:src/App.tsx:100:113

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command

If I add the extension schema to be part of the main schema there are no problems compiling it.

ellemedit commented 2 years ago

In relay-compiler document, we can set 'schemaExtensions' option. After setting 'schemaExtensions', my client schema extension worked. I guess the documentation need explicit explanation.

alunyov commented 2 years ago

Thanks for reporting. I think @Beingbook is right, and we need to update documentation to mention the schemaExtensions in the compiler configuration.

rokn commented 2 years ago

Yup, adding a folder which contains the schema extensions to the schemaExtensions property in my package.json worked.

captbaritone commented 2 years ago

Thanks for the report @rokn and the solution @Beingbook. Would either of you like to like to contribute a fix to the docs?

ellemedit commented 2 years ago

Let me try documentation coming week.