Allow to specify field type as a string
See original GitHub issueCurrently
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
typesarray, add them intotypeMap - Walk over
Query,Mutation,Subscriptionrecursively and resolve types
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Modify or change the data type setting for a field
Convert to this type From this type Changes or restrictions
Text Memo Access deletes all but the first 255 characters.
Number No restrictions.
Currency No restrictions....
Read more >Field data types | Elasticsearch Guide [8.5]
Each field has a field data type, or field type. This type indicates the kind of data the field contains, such as strings...
Read more >Only allow text field to contain certain string values
I'm new to Prisma - I'm using it with a PostgreSQL database. I have a table in my database that has a string...
Read more >Changing or converting field type 'string' to 'reference' on ...
"Type change not allowed. Invalid type conversion for field 'assigned_to' on table 'task'. Cannot convert from 'String' to 'Reference'.
Read more >Custom Field Types
Allows users to enter up to 131,072 characters that display on separate lines similar to a Description field. You can set the length...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m trying to split my types in many packages and it is hard to do using type instances when you can’t avoid circular references in types (most GraphQL schemas that I know).
thunk solves part of this, but it makes it hard to add or remove fields to existing types
you can do something like this
addFields(graphqlObjecttypes, newFields)because it would cause a circular dep to resolve the thunk when adding new fieldswe could have a helper to handle both
stringand graphql object typeSo, is this something you guys want to see in graphql.js? just don’t want to waste time in case you are against it 😃