ardatan / ardatan/graphql-import

Importing named type conflicts with import * from same file, depending on order of imports

Open
#182 6 comments 5 reactions 0 assignees View on GitHub
bug waiting for answer
Dominant language
No language data
Stars
864
Forks
53
PR merge metrics
No merged PRs in 30d

Description

I'm using type extension in my project and just ran into an issue that took me a while to figure out. I was following along with the comments in [Type extension does not work](https://github.com/prismagraphql/graphql-import/issues/42) and found an issue where importing named vs. wildcard types from the same file can result in the wildcard import being clobbered, based on the order that the referencing items are imported.

Consider the following type definitions:
**SomeType.graphql**
```
type SomeType {
name: String!
}

type Mutation {
changeSomeType(name: String!): SomeType
}
```

**Mutation.graphql**
```
# import Mutation.* from './SomeType.graphql'
```

**Query.graphql**
```
# import SomeType from './SomeType.graphql

type Query {
getMyType: SomeType
}
```

If the definition using the named import is imported first, as in this example:
**Schema.graphql**
```
# import Query from './Query.graphql'
# import Mutation from './Mutation.graphql'

type Schema {
query: Query,
mutation: Mutation
}
```
Running this code will return an error `"Mutation" defined in resolvers, but not in schema`

However, if the definition using the wildcard import is imported first, as in this example:
**Schema.graphql**
```
# import Mutation from './Mutation.graphql'
# import Query from './Query.graphql'

type Schema {
query: Query,
mutation: Mutation
}
```
The code will run fine.

I imagine there's some filename-based caching or de-duping going on. Not sure whether this is intentional behavior, but if it is I'd recommend clarifying in the import documentation.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the behavior using SomeType.graphql, Mutation.graphql, Query.graphql, and the two Schema.graphql import orders shown in the issue. Start by tracing the import resolution and filename de-duplication path, then verify that either order preserves both named and wildcard imports without the resolver/schema error.

Written by the indexing model from the issue text.

Assessment

Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.