fix(modules-sdk): Fix remote query selection (#6989)

Fix remote query selection for different relations levels as part of a single processed query
This commit is contained in:
Adrien de Peretti
2024-04-07 16:07:31 +02:00
committed by GitHub
parent 4d6306f57b
commit 667c8609cc
4 changed files with 124 additions and 49 deletions

View File

@@ -1,47 +0,0 @@
import { RemoteQuery } from "../remote-query"
describe("Remote query", () => {
it("should properly handle fields and relations transformation", () => {
const expand = {
fields: ["name", "age"],
expands: {
friend: {
fields: ["name"],
expands: {
ball: {
fields: ["*"],
},
},
},
},
}
const result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: ["name", "age", "friend.name"],
relations: ["friend", "friend.ball"],
args: {
"": undefined,
friend: undefined,
"friend.ball": undefined,
},
})
})
it("should properly handle fields and relations transformation for top level entity", () => {
const expand = {
fields: ["*"],
}
const result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: undefined,
relations: [],
args: {
"": undefined,
},
})
})
})

View File

@@ -0,0 +1,109 @@
import { RemoteQuery } from "../remote-query"
describe("Remote query", () => {
it("should properly handle fields and relations transformation", () => {
let expand = {
fields: ["name", "age"],
expands: {
friend: {
fields: ["name"],
expands: {
ball: {
fields: ["*"],
},
},
},
},
}
let result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: ["name", "age", "friend.name"],
relations: ["friend", "friend.ball"],
args: {
"": undefined,
friend: undefined,
"friend.ball": undefined,
},
})
expand = {
fields: [],
expands: {
friend: {
fields: ["name"],
expands: {
ball: {
fields: ["*"],
},
},
},
},
}
result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: ["friend.name"],
relations: ["friend", "friend.ball"],
args: {
"": undefined,
friend: undefined,
"friend.ball": undefined,
},
})
expand = {
fields: [],
expands: {
friend: {
fields: ["*"],
expands: {
ball: {
fields: ["*"],
},
},
},
},
}
result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: [],
relations: ["friend", "friend.ball"],
args: {
"": undefined,
friend: undefined,
"friend.ball": undefined,
},
})
expand = {
fields: [],
expands: {
friend: {
fields: [],
expands: {
ball: {
fields: ["*"],
},
},
},
},
}
result = RemoteQuery.getAllFieldsAndRelations(expand)
expect(result).toEqual({
select: [],
relations: ["friend", "friend.ball"],
args: {
"": undefined,
friend: undefined,
"friend.ball": undefined,
},
})
})
})