-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: GraphQL query & resolver for loading the primary shop #4747
feat: GraphQL query & resolver for loading the primary shop #4747
Conversation
…rce/reaction into feat-4727-dancastellon-primaryShop-query
export default async function primaryShopId(_, __, context) { | ||
const shopId = await context.queries.primaryShopId(context.collections); | ||
const shop = await context.queries.shopById(context, shopId); | ||
return shop; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice and simple, but it does two Shops.findOne
calls when we often could do just one. You can make a separate primaryShop
query function that does:
const domain = url.parse(context.rootUrl).hostname;
let shop = await Shops.findOne({ domains: domain });
if (!shop) {
shop = await Shops.findOne({ shopType: "primary" });
}
return shop;
And then call that in this resolver
* @param {Object} parentObject - unused | ||
* @param {Object} args - unused | ||
* @param {Object} context - an object containing the per-request state | ||
* @return {Promise<o>} The shop, based on the domain in ROOT_URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should say Promise<Object>
* @param {Object} context - an object containing the per-request state | ||
* @return {Promise<o>} The shop, based on the domain in ROOT_URL | ||
*/ | ||
export default async function primaryShopId(_, __, context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function name should be primaryShop
Resolves #4727
Impact: minor
Type: feature
Solution
This PR adds a
primaryShop
GraphQL query & resolver, eliminating the need to first query for the primary shop ID, followed by another query for shop by ID.Breaking changes
None
Testing