fix(): handle empty q filters - allow to query deleted records from graph API - staled_at fixes (#11544)

* fix(): Allow to query deleted records from graph API

* fix(): Allow to query deleted records from graph API

* handle empty q value

* update staled at sync

* rename integration tests file

* Create strong-houses-marry.md

* try to fix flacky tests

* fix pricing context

* update changeset

* update changeset

* fix import

* skip test for now

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2025-02-21 13:24:12 +01:00
committed by GitHub
parent cfffd55ae6
commit 065df75e7d
10 changed files with 239 additions and 131 deletions

View File

@@ -237,4 +237,93 @@ describe("toRemoteQuery", () => {
},
})
})
it("should transform a query with filters, context and withDeleted into remote query input", () => {
const langContext = QueryContext({
context: {
lang: "pt-br",
},
})
const format = toRemoteQuery(
{
entity: "product",
fields: [
"id",
"title",
"description",
"translation.*",
"categories.*",
"categories.translation.*",
"variants.*",
"variants.translation.*",
],
filters: {
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
},
context: {
translation: langContext,
categories: {
translation: langContext,
},
variants: {
translation: langContext,
},
},
withDeleted: true,
},
entitiesMap
)
expect(format).toEqual({
product: {
__fields: ["id", "title", "description"],
__args: {
filters: {
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
},
withDeleted: true,
},
translation: {
__args: {
context: {
context: {
lang: "pt-br",
},
},
withDeleted: true,
},
__fields: ["*"],
},
categories: {
translation: {
__args: {
context: {
context: {
lang: "pt-br",
},
},
withDeleted: true,
},
__fields: ["*"],
},
__fields: ["*"],
},
variants: {
translation: {
__args: {
context: {
context: {
lang: "pt-br",
},
},
withDeleted: true,
},
__fields: ["*"],
},
__fields: ["*"],
},
},
})
})
})

View File

@@ -36,10 +36,17 @@ export function toRemoteQuery<const TEntity extends string>(
filters?: RemoteQueryFilters<TEntity>
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>
context?: Record<string, any>
withDeleted?: boolean
},
entitiesMap: Map<string, any>
): RemoteQueryGraph<TEntity> {
const { entity, fields = [], filters = {}, context = {} } = config
const {
entity,
fields = [],
filters = {},
context = {},
withDeleted,
} = config
const joinerQuery: Record<string, any> = {
[entity]: {
@@ -69,10 +76,16 @@ export function toRemoteQuery<const TEntity extends string>(
if (topLevel) {
target[ARGUMENTS] ??= {}
target[ARGUMENTS][prop] = normalizedFilters
if (withDeleted) {
target[ARGUMENTS]["withDeleted"] = true
}
} else {
target[key] ??= {}
target[key][ARGUMENTS] ??= {}
target[key][ARGUMENTS][prop] = normalizedFilters
if (withDeleted) {
target[key][ARGUMENTS]["withDeleted"] = true
}
}
} else {
if (!topLevel) {
@@ -117,6 +130,11 @@ export function toRemoteQuery<const TEntity extends string>(
}
}
if (withDeleted) {
joinerQuery[entity][ARGUMENTS] ??= {} as any
joinerQuery[entity][ARGUMENTS]["withDeleted"] = true
}
parseAndAssignFilters(
{
entryPoint: entity,