gqtx icon indicating copy to clipboard operation
gqtx copied to clipboard

Lazy fields declaration

Open f15u opened this issue 3 years ago • 1 comments

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

f15u avatar Apr 06 '21 18:04 f15u

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

Jomik avatar Jun 11 '21 22:06 Jomik