'GraphQL grouping multiple fields of another type
I have the following type
type Build {
slot0Item: Item
slot1Item: Item
slot2Item: Item
slot3Item: Item
primaryKeystone: Keystone
secondaryKeystone: Keystone
resolveKeystone: Keystone
}
Which I'm trying to restructure by grouping related fields under a common field. I'd like it to look something like this:
type Build {
items {
slot0: Item
slot1: Item
slot2: Item
slot3: Item
}
keystones {
primary: Keystone
secondary: Keystone
resolve: Keystone
}
}
(1.) I've tried two approaches so far, first is to introduce a new type *Slots
type ItemSlots {
slot0: Item
slot1: Item
slot2: Item
slot3: Item
}
type KeystoneSlots {
primary: Keystone
secondary: Keystone
resolve: Keystone
}
type Build {
items: ItemSlots!
keystones: KeystoneSlots!
}
But with the above approach, fields of *Slots types have to be mentioned individually to be returned with the query result, and I'd like them to always be returned.
(2.) So I tried defining ItemSlots and KeystoneSlots as scalars, with which I'm able to always return all fields, but now I cannot specify what fields of Item and Keystone should be included.
Approach (1.) seems to be the best so far, but is there a way to query the fields items and keystones as if they were an array, but the returned results are (key->value) objects?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
