Dependencies from package.json
"dependencies": {
"apollo-server-express": "^2.2.6",
"express": "^4.16.4",
"graphql": "^14.0.2"
},
"devDependencies": {
"@types/graphql": "^14.0.3",
"apollo": "^2.1.7",
"nodemon": "^1.18.7",
"npm-run-all": "^4.1.5",
"ts-node": "^7.0.1",
"typescript": "^3.2.2"
}
Generate schema.json (successful):
apollo service:download --endpoint=http://localhost:9898/graphql
✔ Loading Apollo Project
✔ Saving schema to schema.json
✨ Done in 0.85s.
Generate types (unsuccessful):
apollo client:codegen --target=typescript --localSchemaFile='./schema.json'
{ Error: Error in "Loading schema for Unnamed Project": Type "Mutation" already exists in the schema. It cannot also be defined in this type definition.
file:///.../src/schema/mutations/mutation.ts (5:3)
4: # Mutations
5: type Mutation {
^
6: setFakeStatus(status: String!): String
I get the same problem if I try to generate the type in a single step using apollo client:codegen and the endpoint flag. Playground works perfectly and I only define mutation once.
Thoughts?
Looks like apollo client:codegen walks the src tree and that's why it sees 2 definitions of the mutation - one from schema.json and the other from the src tree. Closing for now.
I have the same issue, i need local schema to be outside of src folder to avoid it.
I'm using CRA and importing schema for mocking during development, so imported file should be inside src.
Reopen?
This should not be closed. It is inconvenient that it is not possible (as I know) to avoid the tool to read beyond the specific file specified under localSchemaFile. I suggest having another parameter to turn on/off the capability.
Yes, the issue should be reopened, I see error even if I explicitly exclude schema:
module.exports = {
client: {
service: {
name: 'rkta-apollo',
excludes: ['./src/**.spec.*', 'src/graphql/typeDefs/index.graphql'],
localSchemaFile: 'src/graphql/typeDefs/index.graphql',
},
},
};

wtf is this bullshit error?
Reopening per request...
Hi everyone!
config.client.service.excludes isn't a valid config option. If you want to exclude your schema files, you should place those excludes under the config.client.excludes. To my knowledge, that looks like what's going on here. Sorry the documentation isn't clear on that!
I'm going to close this, since I suspect this is working as designed, but if not I'll reopen if someone can provide me a repo and steps to reproduce!
Took me a while to figure out, I have to exclude the input schema apparently. Doesn't make any sense to me, but it does solve the issue.
This is my config:
module.exports = {
client: {
service: {
name: 'graphql-backend',
includes: ['src/**/*.ts{,x}'],
localSchemaFile: 'src/__generated__/schema.graphql'
},
excludes: ['src/__generated__/schema.graphql']
}
};
I was getting this error doing something of the sort:
const apollo = require("apollo-server-express");
makeExecutableSchema({
typeDefs: [
apollo.gql`type Query`,
apollo.gql`extend type Query {bad: Boolean}`
}
})
The above code is totally valid, but I was getting errors about the type Query.bad being a duplicate :/
I removed my package-lock.json and nuked my node_modules/ and things started working again after npm install.
Most helpful comment
Yes, the issue should be reopened, I see error even if I explicitly exclude schema: