Created
October 3, 2020 17:30
-
-
Save jsoneaday/f840603f57652ff146f59247d13a2c70 to your computer and use it in GitHub Desktop.
Resolvers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IResolvers } from "apollo-server-express"; | |
import { addCar, getAllVehicles, getCars } from "../dataService"; | |
import { Boat, Car, Truck } from "../types/Entities"; | |
import { GqlContext } from "./GqlContext"; | |
const resolvers: IResolvers = { | |
SearchResult: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
if (obj.wheelCount && obj.passengerCount) return "Car"; | |
if (obj.wheelCount && obj.maxPayload) return "Truck"; | |
if (obj.passengerCount) return "Boat"; | |
return "Car"; | |
}, | |
}, | |
IVehicle: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
if (obj.wheelCount && obj.passengerCount) return "Car"; | |
if (obj.wheelCount && obj.maxPayload) return "Truck"; | |
if (obj.passengerCount) return "Boat"; | |
return "Car"; | |
}, | |
}, | |
IPassengerVehicle: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
if (obj.wheelCount && obj.passengerCount) { | |
return "Car"; | |
} | |
return "Boat"; | |
}, | |
}, | |
IWorkVehicle: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
return "Truck"; | |
}, | |
}, | |
ILandVehicle: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
if (obj.wheelCount && obj.passengerCount) { | |
return "Car"; | |
} | |
return "Truck"; | |
}, | |
}, | |
Query: { | |
getAllVehicles: async ( | |
obj: any, | |
args: null, | |
ctx: GqlContext, | |
info: any | |
): Promise<Array<Car | Truck | Boat>> => { | |
return getAllVehicles(); | |
}, | |
}, | |
}; | |
export default resolvers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment