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 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.
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 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
Mutation.graphql
Query.graphql
If the definition using the named import is imported first, as in this example:
Schema.graphql
Running this code will return an error
"Mutation" defined in resolvers, but not in schemaHowever, if the definition using the wildcard import is imported first, as in this example:
Schema.graphql
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.