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: Application types generation from project GQL schema's #8995

Merged
merged 43 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4fef9b4
feat(cli): graphql to ts types
adrien2p Sep 3, 2024
eca6d03
Include field aliases management graphql
adrien2p Sep 3, 2024
e22c604
WIP
adrien2p Sep 3, 2024
904fb29
WIP
adrien2p Sep 3, 2024
7c22c7e
WIP
adrien2p Sep 3, 2024
9f49736
finalise
adrien2p Sep 3, 2024
f7319a8
cleanup CLI func
adrien2p Sep 4, 2024
ec34651
continue clean up + hot reload management
adrien2p Sep 4, 2024
442341a
Merge branch 'develop' into feat/gql-to-types
adrien2p Sep 4, 2024
b972ea0
WIP
adrien2p Sep 4, 2024
b2974f2
Add support for return type
adrien2p Sep 4, 2024
6db5f0c
only reload types in dev
adrien2p Sep 4, 2024
3476b89
rm unsused container
adrien2p Sep 4, 2024
dab54ad
Merge branch 'develop' into feat/gql-to-types
adrien2p Sep 4, 2024
40ea455
__value
carlos-r-l-rodrigues Sep 4, 2024
6cfb5e6
unit test
carlos-r-l-rodrigues Sep 4, 2024
b99db53
fulfillment test
carlos-r-l-rodrigues Sep 4, 2024
7fcbea7
test
carlos-r-l-rodrigues Sep 4, 2024
e635f07
nested pick
adrien2p Sep 5, 2024
70b2a7f
Merge branch 'feat/gql-to-types' of github.com:medusajs/medusa into f…
adrien2p Sep 5, 2024
18b7e1c
move things arround
adrien2p Sep 5, 2024
e384ba0
Include tests as part of the build script
adrien2p Sep 5, 2024
3fbec34
start adding typed tests
adrien2p Sep 5, 2024
b4539b9
cleanup
adrien2p Sep 5, 2024
1e73fc5
resolve conflicts
adrien2p Sep 5, 2024
f053264
cleanup
adrien2p Sep 5, 2024
29d5831
chore: add graphql schema from dtos (#9017)
carlos-r-l-rodrigues Sep 5, 2024
d7926b7
finalise
adrien2p Sep 5, 2024
a3b3327
differenciate date and metadata
adrien2p Sep 5, 2024
01b3ad4
multiple linkable keys for same entity
carlos-r-l-rodrigues Sep 5, 2024
a743d7f
revert linkable type
carlos-r-l-rodrigues Sep 5, 2024
42f15ca
api key test
carlos-r-l-rodrigues Sep 5, 2024
88d1aa3
product test
carlos-r-l-rodrigues Sep 5, 2024
6e09b4c
payment
carlos-r-l-rodrigues Sep 5, 2024
6f1da9b
order test
carlos-r-l-rodrigues Sep 5, 2024
f324f23
Merge branch 'develop' into feat/gql-to-types
carlos-r-l-rodrigues Sep 5, 2024
0fc4df2
fulfillment
carlos-r-l-rodrigues Sep 5, 2024
dee68bc
refactor: remove gql-to-ts command
thetutlage Sep 6, 2024
d32df3a
refactor: move types to .medusa directory in the root of project
thetutlage Sep 6, 2024
dcd7725
refactor: fix identation of generated interface
thetutlage Sep 6, 2024
218f0f5
feat: add CLI flags to generate/disable types generation
thetutlage Sep 6, 2024
4fd0099
Merge branch 'develop' into feat/gql-to-types
thetutlage Sep 6, 2024
2ed690f
Merge branch 'develop' into feat/gql-to-types
thetutlage Sep 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ medusaIntegrationTestRunner({
},
},
},
undefined,
{ throwIfKeyNotFound: true }
)

Expand Down Expand Up @@ -127,7 +126,6 @@ medusaIntegrationTestRunner({
},
},
},
undefined,
{
throwIfRelationNotFound: true,
}
Expand Down Expand Up @@ -171,7 +169,6 @@ medusaIntegrationTestRunner({
},
},
},
undefined,
{
throwIfRelationNotFound: [Modules.PAYMENT],
}
Expand Down
66 changes: 40 additions & 26 deletions packages/cli/medusa-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,26 @@ function buildLocalCommands(cli, isLocalProject) {
command: `develop`,
desc: `Start development server. Watches file and rebuilds when something changes`,
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
default: defaultHost,
describe: `Set host. Defaults to ${defaultHost}`,
}).option(`p`, {
alias: `port`,
type: `string`,
default: process.env.PORT || defaultPort,
describe: process.env.PORT
? `Set port. Defaults to ${process.env.PORT} (set by env.PORT) (otherwise defaults ${defaultPort})`
: `Set port. Defaults to ${defaultPort}`,
}),
_.option("types", {
type: "boolean",
default: true,
describe:
"Generate automated types for modules inside the .medusa directory",
})
.option(`H`, {
alias: `host`,
type: `string`,
default: defaultHost,
describe: `Set host. Defaults to ${defaultHost}`,
})
.option(`p`, {
alias: `port`,
type: `string`,
default: process.env.PORT || defaultPort,
describe: process.env.PORT
? `Set port. Defaults to ${process.env.PORT} (set by env.PORT) (otherwise defaults ${defaultPort})`
: `Set port. Defaults to ${defaultPort}`,
}),
handler: handlerP(
getCommandHandler(`develop`, (args, cmd) => {
process.env.NODE_ENV = process.env.NODE_ENV || `development`
Expand All @@ -371,19 +378,26 @@ function buildLocalCommands(cli, isLocalProject) {
command: `start`,
desc: `Start development server.`,
builder: (_) =>
_.option(`H`, {
alias: `host`,
type: `string`,
default: defaultHost,
describe: `Set host. Defaults to ${defaultHost}`,
}).option(`p`, {
alias: `port`,
type: `string`,
default: process.env.PORT || defaultPort,
describe: process.env.PORT
? `Set port. Defaults to ${process.env.PORT} (set by env.PORT) (otherwise defaults ${defaultPort})`
: `Set port. Defaults to ${defaultPort}`,
}),
_.option("types", {
type: "boolean",
default: false,
describe:
"Generate automated types for modules inside the .medusa directory",
})
.option(`H`, {
alias: `host`,
type: `string`,
default: defaultHost,
describe: `Set host. Defaults to ${defaultHost}`,
})
.option(`p`, {
alias: `port`,
type: `string`,
default: process.env.PORT || defaultPort,
describe: process.env.PORT
? `Set port. Defaults to ${process.env.PORT} (set by env.PORT) (otherwise defaults ${defaultPort})`
: `Set port. Defaults to ${defaultPort}`,
}),
handler: handlerP(
getCommandHandler(`start`, (args, cmd) => {
process.env.NODE_ENV = process.env.NODE_ENV || `development`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IPricingModuleService } from "@medusajs/types"
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export interface GetVariantPriceSetsStepInput {
variantIds: string[]
Expand All @@ -24,21 +24,13 @@ export const getVariantPriceSetsStep = createStep(

const remoteQuery = container.resolve("remoteQuery")

const variantPriceSets = await remoteQuery(
{
variant: {
fields: ["id"],
price_set: {
fields: ["id"],
},
},
const variantPriceSets = await remoteQuery({
entryPoint: "variant",
fields: ["id", "price_set.id"],
variables: {
id: data.variantIds,
},
{
variant: {
id: data.variantIds,
},
}
)
})

const notFound: string[] = []
const priceSetIds: string[] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { CartWorkflowDTO } from "@medusajs/types"
import {
ContainerRegistrationKeys,
Modules,
isObject,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ContainerRegistrationKeys, isObject, Modules } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export interface RetrieveCartWithLinksStepInput {
cart_or_cart_id: string | CartWorkflowDTO
Expand All @@ -29,12 +24,17 @@ export const retrieveCartWithLinksStep = createStep(
const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
const query = remoteQueryObjectFromString({
const query = {
entryPoint: Modules.CART,
fields,
})
variables: {
cart: {
id,
},
},
}

const [cart] = await remoteQuery(query, { cart: { id } })
const [cart] = await remoteQuery(query)

return new StepResponse(cart)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Modules,
PromotionActions,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export interface UpdateCartPromotionStepInput {
id: string
Expand Down Expand Up @@ -33,9 +33,10 @@ export const updateCartPromotionsStep = createStep(
)

const existingCartPromotionLinks = await remoteQuery({
cart_promotion: {
__args: { cart_id: [id] },
fields: ["cart_id", "promotion_id"],
entryPoint: "cart_promotion",
fields: ["cart_id", "promotion_id"],
variables: {
cart_id: [id],
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

/**
* The remote query's details.
Expand Down Expand Up @@ -164,7 +164,7 @@ export const useRemoteQueryStep = createStep(
: undefined,
}

const entities = await query(queryObject, undefined, config)
const entities = await query(queryObjectConfig, config)
const result = list ? entities : entities[0]

return new StepResponse(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
LINKS,
Modules,
promiseAll,
remoteQueryObjectFromString,
} from "@medusajs/utils"

export type SetShippingOptionsPriceSetsStepInput = {
Expand All @@ -28,16 +27,14 @@ async function getCurrentShippingOptionPriceSetsLinks(
shippingOptionIds: string[],
{ remoteQuery }: { remoteQuery: RemoteQueryFunction }
): Promise<LinkItems> {
const query = remoteQueryObjectFromString({
const shippingOptionPriceSetLinks = (await remoteQuery({
service: LINKS.ShippingOptionPriceSet,
variables: {
filters: { shipping_option_id: shippingOptionIds },
take: null,
},
fields: ["shipping_option_id", "price_set_id"],
})

const shippingOptionPriceSetLinks = (await remoteQuery(query)) as {
} as any)) as {
shipping_option_id: string
price_set_id: string
}[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
isDefined,
LINKS,
ModuleRegistrationName,
isDefined,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

interface PriceRegionId {
region_id: string
Expand All @@ -33,16 +32,14 @@ async function getCurrentShippingOptionPrices(
): Promise<
{ shipping_option_id: string; price_set_id: string; prices: PriceDTO[] }[]
> {
const query = remoteQueryObjectFromString({
const shippingOptionPrices = (await remoteQuery({
service: LINKS.ShippingOptionPriceSet,
variables: {
filters: { shipping_option_id: shippingOptionIds },
take: null,
},
fields: ["shipping_option_id", "price_set_id", "price_set.prices.*"],
})

const shippingOptionPrices = (await remoteQuery(query)) as {
} as any)) as {
shipping_option_id: string
price_set_id: string
price_set: PriceSetDTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {
ContainerRegistrationKeys,
MedusaError,
ModuleRegistrationName,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export type FulfillmentProviderValidationWorkflowInput = {
id?: string
Expand All @@ -21,7 +20,10 @@ export const validateFulfillmentProvidersStepId =
*/
export const validateFulfillmentProvidersStep = createStep(
validateFulfillmentProvidersStepId,
async (input: FulfillmentProviderValidationWorkflowInput[], { container }) => {
async (
input: FulfillmentProviderValidationWorkflowInput[],
{ container }
) => {
const dataToValidate: {
service_zone_id: string
provider_id: string
Expand Down Expand Up @@ -83,16 +85,14 @@ export const validateFulfillmentProvidersStep = createStep(
)
}

const serviceZoneQuery = remoteQueryObjectFromString({
const serviceZones = await remoteQuery({
entryPoint: "service_zone",
fields: ["id", "fulfillment_set.locations.fulfillment_providers.id"],
variables: {
id: input.map((d) => d.service_zone_id),
},
})

const serviceZones = await remoteQuery(serviceZoneQuery)

const serviceZonesMap = new Map<
string,
ServiceZoneDTO & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
arrayDifference,
ContainerRegistrationKeys,
MedusaError,
arrayDifference,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { createStep } from "@medusajs/workflows-sdk"

Expand All @@ -17,13 +16,11 @@ export const validateInventoryItems = createStep(
ContainerRegistrationKeys.REMOTE_QUERY
)

const query = remoteQueryObjectFromString({
const items = await remoteQuery({
entryPoint: "inventory_item",
variables: { id },
fields: ["id"],
})

const items = await remoteQuery(query)
const diff = arrayDifference(
id,
items.map(({ id }) => id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {
arrayDifference,
ContainerRegistrationKeys,
MedusaError,
arrayDifference,
remoteQueryObjectFromString,
} from "@medusajs/utils"

import { InventoryTypes } from "@medusajs/types"
Expand All @@ -19,16 +18,14 @@ export const validateInventoryLocationsStep = createStep(
ContainerRegistrationKeys.REMOTE_QUERY
)

const locationQuery = remoteQueryObjectFromString({
const stockLocations = await remoteQuery({
entryPoint: "stock_location",
variables: {
id: data.map((d) => d.location_id),
},
fields: ["id"],
})

const stockLocations = await remoteQuery(locationQuery)

const diff = arrayDifference(
data.map((d) => d.location_id),
stockLocations.map((l) => l.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"

export const validateVariantPriceLinksStepId = "validate-variant-price-links"
/**
Expand All @@ -28,13 +24,11 @@ export const validateVariantPriceLinksStep = createStep(
.filter(Boolean)
.flat(1)

const variantPricingLinkQuery = remoteQueryObjectFromString({
const links = await remoteQuery({
entryPoint: "product_variant_price_set",
fields: ["variant_id", "price_set_id"],
variables: { variant_id: variantIds, take: null },
})

const links = await remoteQuery(variantPricingLinkQuery)
const variantPriceSetMap: Record<string, string> = {}

for (const link of links) {
Expand Down
Loading
Loading