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

Type was defined more than once. #175

Open
terion-name opened this issue May 19, 2018 · 1 comment
Open

Type was defined more than once. #175

terion-name opened this issue May 19, 2018 · 1 comment

Comments

@terion-name
Copy link

terion-name commented May 19, 2018

# 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
Copy link

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

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

2 participants