pgutkowski / KGraphQL

Pure Kotlin GraphQL implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is this the right way with using resolvers on a type?

shamresh opened this issue · comments

I have the following type which contains:

 type<VehicleResponse> {
            description = "Gadget returned from original GadgetProxy"

            property(VehicleResponse::gadget) {
                description = "Integer value representing type of vehicle"
            }

            property<InventoryParts?>("inventory") {
                resolver { response, fromDate: LocalDate ->
                    getInventoryParts(response.gadget.stockNumber, fromDate)
                }
            }
        }

I also have :

 query("getInventory") {
            description = "Returns the parts from the inventory."
            resolver { stockNumber: String, fromDate: LocalDate ->
                getInventoryParts(stockNumber, fromDate)
            }.withArgs {
                arg<String> { name = "fromDate"; description = "Date to check inventory stock" }
            }
        }

As you can see there is a bit of duplication (getInventoryParts). So my question is am I using the resolver correctly when defining the schema or can I some how from VehicleResponse go to query("getInventory") rather than creating a resolver in my VehicleResponse type?

This looks correct. All your logic would be in the getInventoryParts function, so calling it from different places is perfectly fine and the recommended way.

Okay, thank you so much.