gqtx
gqtx copied to clipboard
Lazy fields declaration
Problem: while defining some fields, is not possible to use fields defined later in the file.
Possible solution: make field declaration lazy using a function and not a plain array
Example:
const Query = t.queryType({
fields: [
t.field('myType', {
type: myType, // ts(2454): Variable 'event' is used before being assigned.
// ...
})
]
})
const myType = t.objectType({ ... })
const Query = t.queryType({
fields: () => [
t.field('myType', {
type: myType, // It works
// ...
})
]
})
const myType = t.objectType({ ... })
I can submit a PR for this.
PS: in case this would be accepted, we should revert #46
I guess this becomes an issue when you have a Book
with an Author
and the Author
has a list of Book
?
Your example above doesn't really showcase an issue, as you can simply lift myType
up above Query