Created
February 13, 2020 22:03
-
-
Save kylebuildsstuff/f34ea7b9b8e4ff3042c6afbf397bd638 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // cross-sell.graphql.ts | |
| export const crossSellQueryTypeDefinitions = ` | |
| crossSell(crossSellId: Int): CrossSell | |
| productCrossSells(productId: String): [CrossSell!] | |
| `; | |
| export const crossSellTypeDefinitions = ` | |
| type CrossSell { | |
| displaysProductPrice: Boolean | |
| displaysProductTitle: Boolean | |
| id: Int | |
| productId: String | |
| shopId: Int | |
| title: String | |
| type: String | |
| typeValue: String | |
| customCrossSellProductIds: [String!] | |
| } | |
| } | |
| `; | |
| export const buildCrossSellQueryResolvers = () => { | |
| return { | |
| crossSell: async ( | |
| _: any, | |
| args: { crossSellId: number }, | |
| ctx: AppContext, | |
| ): Promise<CrossSell> => { | |
| const { crossSellId } = args; | |
| const crossSell = (await ctx.state.dataLoaders.crossSell | |
| .load(crossSellId) | |
| .catch(error => { | |
| logError(error, ERROR_MESSAGE.CROSS_SELL_FETCH_FAILED, ctx); | |
| ctx.throw(500, getStatusText(500)); | |
| })) as CrossSell; | |
| return crossSell; | |
| }, | |
| export const buildCrossSellResolvers = () => { | |
| return { | |
| CrossSell: { | |
| id: async ( | |
| root: CrossSell, | |
| args: any, | |
| ctx: AppContext, | |
| ): Promise<number> => { | |
| return root.id; | |
| }, | |
| shopId: async ( | |
| root: CrossSell, | |
| args: any, | |
| ctx: AppContext, | |
| ): Promise<number> => { | |
| return root.shopId; | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment