I have a graphql api that wraps multiple software systems. Right now I have all the types listed directly under query with a prefix for the software system. Eventually each software system could have hundreds of types.
query {
ERP_ItemMaster (partId: Int!): ItemMaster
ERP_SalesOrder (doc: Int!): [SalesOrder]
ERP_PurchaseOrder ...
ERP_WorkOrder ...
Warehouse_Type1
Warehouse_Type2
ShopFloor_Type1
ShopFloor_Type2
SupplierQuality_Type1
SupplierQuality_Type2
}
type ItemMaster {
field
field
...
}
type SalesOrder {
field
field
...
}
...
...
This works fine really. When I'm in GraphiQL I start typing "ERP_" for example, and the suggestion box limits it to the types/queries for that system.
I'm wondering if it's possible to add a layer under query to group the types by software system.
When querying, instead of:
query {
ERP_ItemMaster(partId: 12345) {
field1
field2
}
}
I would have:
query {
ERP {
ItemMaster(partId: 12345) {
field1
field2
}
}
}
I'm getting stuck on the resolver at the grouping level - ERP in the example above. It would need to somehow wrap all the resolvers for the sub-types on that system - instead of the one resolver for each type under the top-level query.
The schemas:
type Query {
ERP: ERP
Warehouse: Warehouse
ShopFloor: ShopFloor
SupplierQuality: SupplierQuality
}
type ERP { // What does the resolver look like for this?
ItemMaster(partId: Int!): ItemMaster
SalesOrder (doc: Int!): [SalesOrder]
PurchaseOrder (doc: Int!): [PurchaseOrder]
WorkOrder (doc: Int!): [WorkOrder]
}
type ItemMaster { ... }
type SalesOrder { ... }
type PurchaseOrder { ... }
type WorkOrder { ... }
type Warehouse { ... }
...
...
...
type ShopFloor { ... }
...
...
...
Is it possible? If so, is it even a good idea, and what would the resolver at the grouping level look like?
If you have suggestions on a completely different way to organize it, I'm open to that too. I like the idea of having one end-point and being able to access all the company's data from there, but maybe a separate graphql end-point for each system would be better?
Thank you!