chore(modules-sdk,orchestration): to remote joiner query (#4974)
Helper function to transform js/json object into RemoteJoinerQuery format.
```typescript
toRemoteJoinerQuery({
product: {
fields: ["id", "title"],
__args: {
skip: 0,
},
variants: {
fields: ["id", "title", "handle", "sku"],
shipping_profile: {
profile: {
fields: ["id", "name"],
},
},
},
collections: {
fields: ["id", "title"],
},
},
})
```
outputs:
```
{
alias: "product",
fields: ["id", "title"],
expands: [
{
property: "product.variants",
fields: ["id", "title", "handle", "sku"],
},
{
property: "product.variants.shipping_profile",
},
{
property: "product.variants.shipping_profile.profile",
fields: ["id", "name"],
},
{
property: "product.collections",
fields: ["id", "title"],
},
],
args: [
{
name: "skip",
value: 0,
},
],
};
```
This commit is contained in:
committed by
GitHub
parent
7a12aa04ac
commit
d8649bacaa
147
packages/orchestration/src/__tests__/joiner/helpers.ts
Normal file
147
packages/orchestration/src/__tests__/joiner/helpers.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import { toRemoteJoinerQuery } from "../../joiner/helpers"
|
||||
|
||||
describe("toRemoteJoinerQuery", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("should transform a simple object to a Remote Joiner Query format", async () => {
|
||||
const obj = {
|
||||
product: {
|
||||
fields: ["id", "title", "handle"],
|
||||
},
|
||||
}
|
||||
|
||||
const rjQuery = toRemoteJoinerQuery(obj)
|
||||
|
||||
expect(rjQuery).toEqual({
|
||||
alias: "product",
|
||||
fields: ["id", "title", "handle"],
|
||||
expands: [],
|
||||
})
|
||||
})
|
||||
|
||||
it("should transform a nested object to a Remote Joiner Query format", async () => {
|
||||
const obj = {
|
||||
product: {
|
||||
fields: ["id", "title", "handle"],
|
||||
variants: {
|
||||
fields: ["sku"],
|
||||
shipping_profiles: {
|
||||
profile: {
|
||||
fields: ["id", "name"],
|
||||
},
|
||||
},
|
||||
options: {
|
||||
fields: ["value"],
|
||||
},
|
||||
},
|
||||
options: {
|
||||
fields: ["value", "name"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const rjQuery = toRemoteJoinerQuery(obj)
|
||||
|
||||
expect(rjQuery).toEqual({
|
||||
alias: "product",
|
||||
fields: ["id", "title", "handle"],
|
||||
expands: [
|
||||
{
|
||||
property: "product.variants",
|
||||
fields: ["sku"],
|
||||
},
|
||||
{
|
||||
property: "product.variants.shipping_profiles",
|
||||
},
|
||||
{
|
||||
property: "product.variants.shipping_profiles.profile",
|
||||
fields: ["id", "name"],
|
||||
},
|
||||
{
|
||||
property: "product.variants.options",
|
||||
fields: ["value"],
|
||||
},
|
||||
{
|
||||
property: "product.options",
|
||||
fields: ["value", "name"],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("should transform a nested object with arguments and directives to a Remote Joiner Query format", async () => {
|
||||
const obj = {
|
||||
product: {
|
||||
fields: ["id", "title", "handle"],
|
||||
__args: {
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
},
|
||||
variants: {
|
||||
fields: ["sku"],
|
||||
__directives: {
|
||||
directiveName: "value",
|
||||
},
|
||||
shipping_profiles: {
|
||||
profile: {
|
||||
fields: ["id", "name"],
|
||||
__args: {
|
||||
context: {
|
||||
customer_group: "cg_123",
|
||||
region_id: "US",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const rjQuery = toRemoteJoinerQuery(obj)
|
||||
|
||||
expect(rjQuery).toEqual({
|
||||
alias: "product",
|
||||
fields: ["id", "title", "handle"],
|
||||
expands: [
|
||||
{
|
||||
property: "product.variants",
|
||||
directives: [
|
||||
{
|
||||
name: "directiveName",
|
||||
value: "value",
|
||||
},
|
||||
],
|
||||
fields: ["sku"],
|
||||
},
|
||||
{
|
||||
property: "product.variants.shipping_profiles",
|
||||
},
|
||||
{
|
||||
property: "product.variants.shipping_profiles.profile",
|
||||
args: [
|
||||
{
|
||||
name: "context",
|
||||
value: {
|
||||
customer_group: "cg_123",
|
||||
region_id: "US",
|
||||
},
|
||||
},
|
||||
],
|
||||
fields: ["id", "name"],
|
||||
},
|
||||
],
|
||||
args: [
|
||||
{
|
||||
name: "limit",
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
name: "offset",
|
||||
value: 0,
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user