Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remote Joiner #4098

Merged
merged 45 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4e61c3b
initial commit
carlos-r-l-rodrigues May 10, 2023
9c4fdda
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues May 11, 2023
9b4f114
remote joiner tests
carlos-r-l-rodrigues May 13, 2023
4daea74
Tests and fix of nested grouped properties
carlos-r-l-rodrigues May 15, 2023
d23b10d
yarn.lock
carlos-r-l-rodrigues May 15, 2023
ffd8552
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues May 15, 2023
7a63c4f
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues May 15, 2023
3bc97ec
rem files from other pr
carlos-r-l-rodrigues May 15, 2023
9d78d2d
grouping extends and filter fields fix
carlos-r-l-rodrigues May 18, 2023
61abd3e
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues May 18, 2023
651832e
fix nested expands
carlos-r-l-rodrigues May 18, 2023
e97d3fa
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 18, 2023
50cf37f
es5 compliant
carlos-r-l-rodrigues May 18, 2023
3defa30
remove fields not belonging to the same service
carlos-r-l-rodrigues May 18, 2023
d28c9f3
remove any and parse all GQL types
carlos-r-l-rodrigues May 18, 2023
907ceed
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 19, 2023
81296bd
fix filename
carlos-r-l-rodrigues May 19, 2023
f0e709e
remote fetch data as a callback
carlos-r-l-rodrigues May 22, 2023
6c4bdb1
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 22, 2023
d953a6d
lower case first
carlos-r-l-rodrigues May 22, 2023
c27144b
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 22, 2023
0c8b35b
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 23, 2023
65b6a39
normalize returned data inside property "data" and support multi prop…
carlos-r-l-rodrigues May 23, 2023
36ce524
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 23, 2023
1ac576d
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 23, 2023
4da1de4
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 24, 2023
ba86033
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 24, 2023
de6214c
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 25, 2023
20288b5
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues May 31, 2023
7843150
Add extends to JoinerConfig
carlos-r-l-rodrigues Jun 2, 2023
7a4aab8
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues Jun 2, 2023
52cc537
not undefined
carlos-r-l-rodrigues Jun 2, 2023
11247b1
optional relashionship
carlos-r-l-rodrigues Jun 2, 2023
d8cf449
@medusajs/orchestration
carlos-r-l-rodrigues Jun 2, 2023
43ab516
remove graphql from utils
carlos-r-l-rodrigues Jun 2, 2023
7dfdc42
test all
carlos-r-l-rodrigues Jun 2, 2023
230ec6b
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues Jun 8, 2023
f1023e8
Merge branch 'develop' of github.com:medusajs/medusa into feat/remote…
carlos-r-l-rodrigues Jun 20, 2023
0692549
fix: yarn.lock
carlos-r-l-rodrigues Jun 20, 2023
76e4de9
fix: types update
carlos-r-l-rodrigues Jun 20, 2023
6bbc83c
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues Jun 20, 2023
ce64cfe
Merge branch 'develop' into feat/remote-joiner
carlos-r-l-rodrigues Jun 27, 2023
f157a3f
Merge remote-tracking branch 'origin' into feat/remote-joiner
carlos-r-l-rodrigues Jun 29, 2023
27743cb
Merge branch 'develop' into feat/remote-joiner
olivermrbl Jun 29, 2023
a432608
Create afraid-otters-train.md
olivermrbl Jun 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/afraid-otters-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/orchestration": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat: Remote Joiner
13 changes: 13 additions & 0 deletions packages/orchestration/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
isolatedModules: false,
},
},
transform: {
"^.+\\.[jt]s?$": "ts-jest",
},
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
36 changes: 36 additions & 0 deletions packages/orchestration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@medusajs/orchestration",
"version": "0.0.1",
"description": "Medusa utilities to orchestrate modules",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/orchestration"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/types": "^1.8.7",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typescript": "^4.4.4"
},
"dependencies": {
"@medusajs/utils": "^1.9.1",
"graphql": "^16.6.0"
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"build": "tsc --build",
"watch": "tsc --build --watch",
"test": "jest"
}
}
189 changes: 189 additions & 0 deletions packages/orchestration/src/__fixtures__/joiner/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
export const remoteJoinerData = {
user: [
{
id: 1,
email: "[email protected]",
name: "John Doe",
fullname: "John Doe full name",
products: [
{
id: 1,
product_id: 102,
},
],
nested: {
lala: "lala",
multiple: [
{
abc: 1,
},
{
abc: 2,
},
],
},
},
{
id: 2,
email: "[email protected]",
name: "Jane Doe",
products: [
{
id: 2,
product_id: [101, 102],
},
],
nested: {
lala: "lele",
multiple: [
{
a: 33,
},
{
a: 44,
},
],
},
},
{
id: 3,
email: "[email protected]",
name: "aaa bbb",
fullname: "3333 Doe full name",
nested: {
lala: "lolo",
multiple: [
{
a: 555,
},
{
a: 555,
},
],
},
},
{
id: 4,
email: "[email protected]",
name: "a4444 44 44",
fullname: "444 Doe full name",
products: [
{
id: 4,
product_id: 103,
},
],
nested: {
lala: "lulu",
multiple: [
{
a: 6666,
},
{
a: 7777,
},
],
},
},
],
product: {
rows: [
{
id: 101,
name: "Product 1",
handler: "product-1-handler",
user_id: 2,
},
{
id: 102,
name: "Product 2",
handler: "product-2-handler",
user_id: 1,
},
{
id: 103,
name: "Product 3",
handler: "product-3-handler",
user_id: 3,
},
],
limit: 3,
skip: 0,
},
variant: [
{
id: 991,
name: "Product variant 1",
product_id: 101,
},
{
id: 992,
name: "Product variant 2",
product_id: 101,
},
{
id: 993,
name: "Product variant 33",
product_id: 103,
},
],
order_variant: [
{
order_id: 201,
product_id: 101,
variant_id: 991,
quantity: 1,
},
{
order_id: 201,
product_id: 101,
variant_id: 992,
quantity: 5,
},
{
order_id: 205,
product_id: 101,
variant_id: 992,
quantity: 4,
},
{
order_id: 205,
product_id: 103,
variant_id: 993,
quantity: 1,
},
],
order: [
{
id: 201,
number: "ORD-001",
date: "2023-04-01T12:00:00Z",
products: [
{
product_id: 101,
variant_id: 991,
quantity: 1,
},
{
product_id: 101,
variant_id: 992,
quantity: 5,
},
],
user_id: 4,
},
{
id: 205,
number: "ORD-202",
date: "2023-04-01T12:00:00Z",
products: [
{
product_id: [101, 103],
variant_id: 993,
quantity: 4,
},
],
user_id: 1,
},
],
}
118 changes: 118 additions & 0 deletions packages/orchestration/src/__mocks__/joiner/mock_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { JoinerServiceConfig } from "@medusajs/types"
import { remoteJoinerData } from "./../../__fixtures__/joiner/data"

export const serviceConfigs: JoinerServiceConfig[] = [
{
serviceName: "User",
primaryKeys: ["id"],
relationships: [
{
foreignKey: "products.product_id",
serviceName: "Product",
primaryKey: "id",
alias: "product",
},
],
extends: [
{
serviceName: "Variant",
resolve: {
foreignKey: "user_id",
serviceName: "User",
primaryKey: "id",
alias: "user",
},
},
],
},
{
serviceName: "Product",
primaryKeys: ["id", "sku"],
relationships: [
{
foreignKey: "user_id",
serviceName: "User",
primaryKey: "id",
alias: "user",
},
],
},
{
serviceName: "Variant",
primaryKeys: ["id"],
relationships: [
{
foreignKey: "product_id",
serviceName: "Product",
primaryKey: "id",
alias: "product",
},
{
foreignKey: "variant_id",
primaryKey: "id",
serviceName: "Order",
alias: "orders",
inverse: true, // In an inverted relationship the foreign key is on Order and the primary key is on variant
},
],
},
{
serviceName: "Order",
primaryKeys: ["id"],
relationships: [
{
foreignKey: "product_id",
serviceName: "Product",
primaryKey: "id",
alias: "product",
},
{
foreignKey: "products.variant_id,product_id",
serviceName: "Variant",
primaryKey: "id,product_id",
alias: "variant",
},
{
foreignKey: "user_id",
serviceName: "User",
primaryKey: "id",
alias: "user",
},
],
},
]

export const mockServiceList = (serviceName) => {
return jest.fn().mockImplementation((data) => {
const src = {
userService: remoteJoinerData.user,
productService: remoteJoinerData.product,
variantService: remoteJoinerData.variant,
orderService: remoteJoinerData.order,
}

let resultset = JSON.parse(JSON.stringify(src[serviceName]))

if (
serviceName === "userService" &&
!data.fields?.some((field) => field.includes("multiple"))
) {
resultset = resultset.map((item) => {
delete item.nested.multiple
return item
})
}

return {
data: resultset,
path: serviceName === "productService" ? "rows" : undefined,
}
})
}

export const serviceMock = {
orderService: mockServiceList("orderService"),
userService: mockServiceList("userService"),
productService: mockServiceList("productService"),
variantService: mockServiceList("variantService"),
}
Loading