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:
committed by
GitHub
parent
cfffd55ae6
commit
065df75e7d
@@ -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: ["*"],
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user