Skip to content

Instantly share code, notes, and snippets.

@alfari16
Last active September 7, 2020 07:05
Show Gist options
  • Select an option

  • Save alfari16/e4e98200f7982d23b12f83bd540578d6 to your computer and use it in GitHub Desktop.

Select an option

Save alfari16/e4e98200f7982d23b12f83bd540578d6 to your computer and use it in GitHub Desktop.
// resolvers.ts
import Knex from 'knex';
import {IGraphQLSchemaContext, Merchant} from '../../types';
export default {
Query: {
allMerchants() {
return Knex(config.get('database'))('merchants');
},
},
Merchant: {
products({id: merchantId}: Merchant, _: Record<string, any>, {loaders}: IGraphQLSchemaContext) {
return loaders.getProductsByMerchantId.load(merchantId);
},
location({id: merchantId}: Merchant, _: Record<string, any>, {loaders}: IGraphQLSchemaContext) {
return loaders.getLocationsByMerchantId.load(merchantId);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment