In our schema.graphql, we define a type Address for common address
type Address {
city: String
latitude: Float
longitude: Float
state: String
staticMap: Image
street: String
zip: String
}
It works when we are using 1.4.1 without issues. But today when we upgrade to 1.5.0 (along with relay-runtime/react-relay) we no longer able to compile the static queries.
react-compiler keeps throwing ERROR:
Type "Address" already exists in the schema. It cannot also be defined in this type definition.
After we downgrade to 1.4.1, the compiler works again.
is there only one type Address?
@sibelius Yes, there is only one type Address in the schema.graphql file.
could u create a repo to reproduce this?
@sibelius I'm seeing the same issue. It's not clear what needs to be done to reproduce it, given that the error message is incorrectly stating that the defintion already exists. When I run the compiler with --verbose, I get:
ERROR:
Type "< MyTypeName >" already exists in the schema. It cannot also be defined in this type definition.
From: CodegenRunner.write
at extendSchema (.../node_modules/relay-compiler/node_modules/graphql/utilities/extendSchema.js:82:17)
at .../node_modules/relay-compiler/bin/relay-compiler:4897:13
at Object.run (.../node_modules/relay-compiler/bin/relay-compiler:481:31)
at Object.extendASTSchema (.../node_modules/relay-compiler/bin/relay-compiler:4885:34)
at .../node_modules/relay-compiler/bin/relay-compiler:7613:40
at Generator.next (<anonymous>)
at step (.../node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at .../node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at new Promise (<anonymous>)
at new F (.../node_modules/core-js/library/modules/_export.js:35:28)
Upon inspecting the source code, I see that line 4897 of node_modules/relay-compiler/bin/relay-compiler has a comment written directly above it:
// TODO T24511737 figure out if this is dangerous
Can you add logging statements to the line where it invokes extendSchema to inspect with _what_ it tries to extend your schema?
Otherwise, in order to make a repro, an empty app with your schema should probably suffice, if you can share that.
I am seeing the same issue with a different type definition, also only have one defined.
@alloy @sibelius Here is the repo that I extract from our project. I can reproduce the issue with this.
@nightspirit Because you have wrong args so compiler scans dirs with the schema files. I had the same problem. Check https://github.com/este/este/blob/b60c7a2f8f7c2b78ba4d0a889fee8a78cb2bbd50/package.json#L12
You have to process only dirs without the other schemas. cc @jsteiner Compiler could have a better error message for that.
@steida After I move the schema.graphql out of src directory as well as changing the command. It seems working.
relay-compiler --src ./src --schema schema.graphql
1.4.1 accept the schema.graphql in the src folder. I guess the error is somehow related to "client-only schema extensions" feature. Does it scan the src folder for .graphql files and add additional type to schema definition? The main schema should be excluded from scanning in my opinion.
1.4.1 accept the schema.graphql in the src folder. I guess the error is somehow related to "client-only schema extensions" feature. Does it scan the src folder for .graphql files and add additional type to schema definition? The main schema should be excluded from scanning in my opinion.
@nightspirit I think this is correct! See #2264.
I'm going to update the release note to indicate that this change can break the compiler and see if we can have a better error message for this.
Thanks! And sorry for the trouble!
@jstejada I think we should fix this DX by excluding the --schema path from the found .graphql documents or do you foresee problems with that?
I´m sorry, but it´s not clear to me what should be done. I´m facing the same problem:
ERROR:
Type "Node" already exists in the schema. It cannot also be defined in this type definition.
From: CodegenRunner.write
at extendSchema (D:\dev\app\client\node_modules\graphql\utilities\extendSchema.js:82:17)
at D:\dev\app\client\node_modules\relay-compiler\bin\relay-compiler:4897:13
at Object.run (D:\dev\app\client\node_modules\relay-compiler\bin\relay-compiler:481:31)
at Object.extendASTSchema (D:\dev\app\client\node_modules\relay-compiler\bin\relay-compiler:4885:34)
at D:\dev\app\client\node_modules\relay-compiler\bin\relay-compiler:7613:40
at next (native)
at step (D:\dev\app\client\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
at D:\dev\app\client\node_modules\babel-runtime\helpers\asyncToGenerator.js:35:14
at Promise.F (D:\dev\app\client\node_modules\core-js\library\modules\_export.js:35:28)
at D:\dev\app\client\node_modules\babel-runtime\helpers\asyncToGenerator.js:14:12
And my command:
"relay": "relay-compiler --src ./src --verbose --schema ./src/data/schema.graphql"
My graph ql is generated at tha following folder:
d:\dev\app\client\src\data
Should I change the directory, change parameters or something else ? Please clarify...
@renatonmendes Check https://github.com/este/este for an inspiration.
@steida, hummm... Should I put my schema.graphql in a directory other then src/, as leaving at src/data/ it will be reloaded by the compiler ?
@renatonmendes Yes, the problem is when your schema file resides inside the source root you specify with —src
Going to re-open this and make a fix to improve DX.
Maybe I missed something too, but I am having the same issue. I set my project up exactly how @steida has his setup. Put my schema.graphql file in a server folder. Included my folders that should have generated files in the relay command.
relay-compiler --src . --include 'components/**' 'client/**' --schema server/schema.graphql
Still getting the error, here is a snapshot of my package.json. Also running Node v8.9.3

@ErnestGrey Your server schema exists inside --src, which is why it’s being used as a client schema extension as well.
@alloy My apologies, but I don't follow, I don't have a src folder in my file structure. Do I need one?

I wasn’t clear enough and have updated my comment. I meant the source root that you designate with the --src option.
Getting the same error, now in my monorepo:
"relay": "relay-compiler --verbose --src ./src --schema ../graphql/data/schema.graphql"
My --schema is outside ./src
```
relay-compiler --verbose --src ./src --schema ../graphql/data/schema.graphql
HINT: pass --watch to keep watching for changes.
Writing js
ERROR:
Type "Company" already exists in the schema. It cannot also be defined in this type definition.
From: CodegenRunner.write
at extendSchema (D:\monorepo\node_modules\graphql\utilitiesextendSchema.js:89:17)
at D:\monorepo\node_modules\relay-compiler\bin\relay-compiler:4897:13
at Object.run (D:\monorepo\node_modules\relay-compiler\bin\relay-compiler:481:31)
at Object.extendASTSchema (D:\monorepo\node_modules\relay-compiler\bin\relay-compiler:4885:34)
at D:\monorepo\node_modules\relay-compiler\bin\relay-compiler:7613:40
at next (native)
at step (D:\monorepo\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
at D:\monorepo\node_modules\babel-runtime\helpers\asyncToGenerator.js:35:14
at Promise.F (D:\monorepo\node_modules\core-js\library\modules_export.js:35:28)
at D:\monorepo\node_modules\babel-runtime\helpers\asyncToGenerator.js:14:12
npm ERR! code ELIFECYCLE
npm ERR! errno 100
npm ERR! @monorepo/[email protected] relay: relay-compiler --verbose --src ./src --schema ../graphql/data/schema.graphql
npm ERR! Exit status 100
``
Isn´t that a bug, as myschema.graphqlresides outside the./srcfolder, at../graphql/data/schema.graphql` ?
That seems suspicious indeed. If you grep ./src/**/*.graphql for Company, what occurrences do you find?
Case closed and problem solved. There was an old schema.graphql with Company definition deep inside the srcfolder. Interesting is that this is not the schema.graphql file that relay-compiler was called- the one at ../graphql/data/schema.graphql - but an old and totally different one.
To finish I would like to leave 3 suggestions:
a) Really bypass the current file that is being processed. Why parse the file that we know cannot be parsed?
b) Print, on verbose, what files are being processed. That way we will know on each file and path we have a problem. Remember that some projects has tons of folders and files (like mine)
c) Change this error message with something like: There may be a graphql file being processed in the src folder.
Is the correct work around, for now, not to have the schema file in the src directory specified for the relay-compiler?
@mvachhar Yes.
@renatonmendes
*.graphql files to be processed, _except_ for the --schema one, which is fixed in https://github.com/facebook/relay/pull/2361node_modules/.bin/relay-compiler --src ./src/ --schema ./schema.graphql
Error: Cannot find module 'graphql'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
Most helpful comment
@steida After I move the schema.graphql out of src directory as well as changing the command. It seems working.
1.4.1 accept the schema.graphql in the src folder. I guess the error is somehow related to "client-only schema extensions" feature. Does it scan the src folder for .graphql files and add additional type to schema definition? The main schema should be excluded from scanning in my opinion.