-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
Description
Currently
graphql.js expects type
option to be an instance of GraphQLType (GraphQLInputObjectType
, GraphQLObjectType
, etc).
Example:
const AnotherType = new GraphQLObjectType({ ... })
const Type = new GraphQLObjectType({
name: 'MyType',
fields: {
anotherType: { type: AnotherType }
}
})
Desired
In order to split application into modules (which may have circular references in GraphQL types) it'd be helpful to be able to specify type
parameter in fields as a string. Updated example:
const Type = new GraphQLObjectType({
name: 'MyType',
fields: {
anotherType: { type: 'AnotherType' } // AnotherType is referenced by its name
}
})
Workaround
Currently when nodejs modules have circular reference, I can use ugly workaround: calling require
in fields
thunk:
const Type = new GraphQLObjectType({
name: 'MyType',
fields: () => ({
anotherType: { type: require('anotherModule').AnotherType }
})
})
Implementation details
We can add a restriction, that types which a referenced by their name must be included in types
option of GraphQLSchema
constructor:
const schema = new GraphQLSchema({
types: [/* specify types that were referenced by their name */],
query: ...,
mutation: ...
subscription: ...
})
So, then the flow is this:
- Walk over
types
array, add them intotypeMap
- Walk over
Query
,Mutation
,Subscription
recursively and resolve types
sibelius and stalniy