Skip to content

Commit

Permalink
Merge pull request #2494 from graphcommerce-org/feature/algolia-preve…
Browse files Browse the repository at this point in the history
…nt-groupid-error

Feature/algolia prevent groupid error in login
  • Loading branch information
paales authored Feb 7, 2025
2 parents 000b211 + fd824d4 commit 932adc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-rivers-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/algolia-products": patch
---

Solve issue when creating an account the group_id would be requested but there wansn't a token available to retrieve the group_id.
19 changes: 18 additions & 1 deletion packages/algolia-products/mesh/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AlgoliasearchResponse, Resolvers } from '@graphcommerce/graphql-mesh'
import type { AlgoliasearchResponse, MeshContext, Resolvers } from '@graphcommerce/graphql-mesh'
import { hasSelectionSetPath } from '@graphcommerce/graphql-mesh'
import type { GraphQLError, GraphQLResolveInfo } from 'graphql'
import { algoliaFacetsToAggregations, getCategoryList } from './algoliaFacetsToAggregations'
Expand Down Expand Up @@ -97,6 +97,23 @@ export const resolvers: Resolvers = {
return items
},
},
Customer: {
group_id: {
resolve: async (root, args, context, info) => {
const { headers } = context as MeshContext & {
headers?: Record<string, string | undefined>
}
if (!headers?.authorization) return 0
const customer = await context.m2rest.Query.m2rest_GetV1CustomersMe({
root,
context,
info,
autoSelectionSetWithDepth: 10,
})
return customer?.group_id ?? null
},
},
},
Query: {
products: async (root, args, context, info) => {
const isAgolia = (args.filter?.engine?.in ?? [args.filter?.engine?.eq])[0] === 'algolia'
Expand Down

This file was deleted.

0 comments on commit 932adc5

Please sign in to comment.