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

[relay-compiler] After upgrade to 1.5.0, it throws ERROR: Type "Address" already exists in the schema. It cannot also be defined in this type definition. #2346

Closed
nightspirit opened this issue Feb 23, 2018 · 28 comments

Comments

@nightspirit
Copy link
Contributor

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.

@sibelius
Copy link
Contributor

is there only one type Address?

@nightspirit
Copy link
Contributor Author

@sibelius Yes, there is only one type Address in the schema.graphql file.

@sibelius
Copy link
Contributor

could u create a repo to reproduce this?

@obibring
Copy link

@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

@alloy
Copy link
Contributor

alloy commented Feb 23, 2018

Can you add logging statements to the line where it invokes extendSchema to inspect with what it tries to extend your schema?

@alloy
Copy link
Contributor

alloy commented Feb 23, 2018

Otherwise, in order to make a repro, an empty app with your schema should probably suffice, if you can share that.

@fllamo
Copy link

fllamo commented Feb 23, 2018

I am seeing the same issue with a different type definition, also only have one defined.

@nightspirit
Copy link
Contributor Author

@alloy @sibelius Here is the repo that I extract from our project. I can reproduce the issue with this.

@steida
Copy link

steida commented Feb 23, 2018

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

@nightspirit
Copy link
Contributor Author

nightspirit commented Feb 23, 2018

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

@jstejada
Copy link
Contributor

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!

@alloy
Copy link
Contributor

alloy commented Feb 26, 2018

@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?

@renatonmendes
Copy link

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

@steida
Copy link

steida commented Mar 2, 2018

@renatonmendes Check https://github.com/este/este for an inspiration.

@renatonmendes
Copy link

renatonmendes commented Mar 2, 2018

@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 ?

@alloy
Copy link
Contributor

alloy commented Mar 3, 2018

@renatonmendes Yes, the problem is when your schema file resides inside the source root you specify with —src

@alloy
Copy link
Contributor

alloy commented Mar 6, 2018

Going to re-open this and make a fix to improve DX.

@ErnestGrey
Copy link

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

screen shot 2018-03-08 at 2 10 08 pm

@alloy
Copy link
Contributor

alloy commented Mar 8, 2018

@ErnestGrey Your server schema exists inside --src, which is why it’s being used as a client schema extension as well.

@ErnestGrey
Copy link

@alloy My apologies, but I don't follow, I don't have a src folder in my file structure. Do I need one?
screen shot 2018-03-08 at 4 45 46 pm

@alloy
Copy link
Contributor

alloy commented Mar 8, 2018

I wasn’t clear enough and have updated my comment. I meant the source root that you designate with the --src option.

@renatonmendes
Copy link

renatonmendes commented Mar 22, 2018

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\utilities\extendSchema.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/editor@3.0.0 relay: `relay-compiler --verbose --src ./src --schema ../graphql/data/schema.graphql`
npm ERR! Exit status 100

Isn´t that a bug, as my schema.graphql resides outside the ./src folder, at ../graphql/data/schema.graphql ?

@alloy
Copy link
Contributor

alloy commented Mar 22, 2018

That seems suspicious indeed. If you grep ./src/**/*.graphql for Company, what occurrences do you find?

@renatonmendes
Copy link

renatonmendes commented Mar 22, 2018

Case closed and problem solved. There was an old schema.graphql with Company definition deep inside the src folder. 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.

@mvachhar
Copy link

mvachhar commented Apr 9, 2018

Is the correct work around, for now, not to have the schema file in the src directory specified for the relay-compiler?

@alloy
Copy link
Contributor

alloy commented Apr 9, 2018

@mvachhar Yes.

@alloy
Copy link
Contributor

alloy commented Apr 9, 2018

@renatonmendes

@antimtechnology
Copy link

node_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. (D:\ReactNative\RelayAndGraphQL\frontend\node_modules\graphql-compiler\lib\GraphQLSchemaUtils.js:153:20)
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)

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