Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

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

Closed
shamresh opened this issue Feb 8, 2019 · 2 comments
Closed

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

shamresh opened this issue Feb 8, 2019 · 2 comments

Comments

@shamresh
Copy link

shamresh commented Feb 8, 2019

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?

@jeggy
Copy link
Contributor

jeggy commented Feb 11, 2019

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.

@shamresh
Copy link
Author

Okay, thank you so much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants