Type was defined more than once.
Opened this issue · 1 comments
terion-name commented
# import Article from "./generated-schema.graphql"
type Mutation {
createArticle(data: ArticleCreateInput!): Article
deleteArticle(id: ID!): Article
}
and
# import Article from "./generated-schema.graphql"
type Query {
articles(
where: ArticleWhereInput
orderBy: ArticleOrderByInput
skip: Int
after: String
before: String
first: Int
last: Int
): [Article!]!
}
const server = new GraphQLServer({
typeDefs: ["schema/application-schema.graphql", "schema/admin-schema.graphql"],
resolvers,
context: {db: await getPrismaInstance()}
});
Leads to Type "Article" was defined more than once.
Removing imports from there and extracting them to separate file and then:
typeDefs: ["schema/imports.graphql", "schema/application-schema.graphql", "schema/admin-schema.graphql"],
Leads to Field articles: Couldn't find type Article in any of the schemas.
Is there a way to handle this?
PS
No, I can't do like this:
# import Article, ArticleWhereInput, ArticleOrderByInput, ArticleCreateInput from "./generated-schema.graphql"
# import * from "./application-schema.graphql"
# import * from "./admin-schema.graphql"
I need conditional import
johndevor commented
I think you might be able to solve this with the merge-graphql-schema package.
// ./graphql/types/index.js
import { mergeTypes } from 'merge-graphql-schemas';
import clientType from './clientType';
import productType from './productType';
const types = [
clientType,
productType,
];
// NOTE: 2nd param is optional, and defaults to false
// Only use if you have defined the same type multiple times in
// different files and wish to attempt merging them together.
export default mergeTypes(types, { all: true });
https://www.npmjs.com/package/merge-graphql-schemas#merging-type-definitions