ardatan / ardatan/graphql-import

Type was defined more than once.

Open
#175 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
864
Forks
53
PR merge metrics
No merged PRs in 30d

Description

```graphql
# import Article from "./generated-schema.graphql"
type Mutation {
createArticle(data: ArticleCreateInput!): Article
deleteArticle(id: ID!): Article
}
```
and
```graphql
# import Article from "./generated-schema.graphql"
type Query {
articles(
where: ArticleWhereInput
orderBy: ArticleOrderByInput
skip: Int
after: String
before: String
first: Int
last: Int
): [Article!]!
}
```
```js
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:

```js
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how GraphQLServer consumes typeDefs from schema/application-schema.graphql, schema/admin-schema.graphql, and schema/imports.graphql, and how the imports from generated-schema.graphql are resolved. The issue is done when conditional imports can be represented without defining Article twice or leaving the articles field unable to find Article.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.