From 358435d715dc6bac7498f805b12b74a45d573330 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Wed, 25 Sep 2024 12:04:25 +0200 Subject: [PATCH] chore: Move graphl to a single place (#9303) * chore: Move graphl to a single place * add new line --- .gitignore | 2 ++ _tsconfig.base.json | 3 +- packages/core/framework/src/index.ts | 2 +- packages/core/modules-sdk/package.json | 1 - packages/core/modules-sdk/src/medusa-app.ts | 7 ++--- .../__fixtures__/get-entities-map.ts | 2 +- packages/core/modules-sdk/src/types/index.ts | 2 -- packages/core/modules-sdk/src/utils/index.ts | 6 ++-- packages/core/orchestration/package.json | 3 +- .../orchestration/src/joiner/remote-joiner.ts | 9 +++--- packages/core/utils/package.json | 2 ++ packages/core/utils/src/bundles.ts | 1 + packages/core/utils/src/common/index.ts | 1 - .../__tests__/clean-graphql-schema.spec.ts | 2 +- .../src/graphql/__tests__}/graphql-ast.ts | 2 +- .../gql-get-fields-and-relations.spec.ts | 2 +- .../utils/graphql-schema-to-fields.ts | 2 +- .../src/graphql/clean-graphql.ts} | 0 .../extract-relations-from-graphql.ts} | 0 .../src/graphql/get-fields-and-relations.ts} | 0 .../src/graphql/graphql-parser.ts} | 7 +++-- .../src/graphql/graphql-to-fields.ts} | 0 .../src/graphql/graphql-to-ts-types.ts} | 20 ++++++++---- packages/core/utils/src/graphql/index.ts | 9 ++++++ packages/core/utils/src/index.ts | 1 + packages/medusa/src/commands/start.ts | 6 ++-- packages/medusa/src/loaders/index.ts | 3 +- .../modules/index/src/utils/build-config.ts | 31 +++++++++---------- .../modules/index/src/utils/gql-to-types.ts | 4 +-- yarn.lock | 10 +++--- 30 files changed, 78 insertions(+), 62 deletions(-) rename packages/core/{modules-sdk/src => utils/src/graphql}/__tests__/clean-graphql-schema.spec.ts (97%) rename packages/core/{orchestration/src/__tests__/joiner => utils/src/graphql/__tests__}/graphql-ast.ts (99%) rename packages/core/{modules-sdk/src => utils/src/graphql}/__tests__/utils/gql-get-fields-and-relations.spec.ts (96%) rename packages/core/{modules-sdk/src => utils/src/graphql}/__tests__/utils/graphql-schema-to-fields.ts (97%) rename packages/core/{modules-sdk/src/utils/clean-graphql-schema.ts => utils/src/graphql/clean-graphql.ts} (100%) rename packages/core/utils/src/{common/graphql-relations-entity-map.ts => graphql/extract-relations-from-graphql.ts} (100%) rename packages/core/{modules-sdk/src/utils/gql-get-fields-and-relations.ts => utils/src/graphql/get-fields-and-relations.ts} (100%) rename packages/core/{orchestration/src/joiner/graphql-ast.ts => utils/src/graphql/graphql-parser.ts} (98%) rename packages/core/{modules-sdk/src/utils/graphql-schema-to-fields.ts => utils/src/graphql/graphql-to-fields.ts} (100%) rename packages/core/{modules-sdk/src/utils/gql-schema-to-types.ts => utils/src/graphql/graphql-to-ts-types.ts} (84%) create mode 100644 packages/core/utils/src/graphql/index.ts diff --git a/.gitignore b/.gitignore index e5fde2f33a..37390fd46d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ build/** **/stats .favorites.json .vscode + +**/tsconfig.tsbuildinfo diff --git a/_tsconfig.base.json b/_tsconfig.base.json index 8c8f0acaf5..7452b366f3 100644 --- a/_tsconfig.base.json +++ b/_tsconfig.base.json @@ -19,7 +19,8 @@ "strictFunctionTypes": true, "noImplicitThis": true, "allowJs": true, - "skipLibCheck": true + "skipLibCheck": true, + "rootDir": "${configDir}/src" }, "include": ["${configDir}/src"], "exclude": ["${configDir}/dist", "${configDir}/node_modules"] diff --git a/packages/core/framework/src/index.ts b/packages/core/framework/src/index.ts index c68e588a56..cc5cf9c261 100644 --- a/packages/core/framework/src/index.ts +++ b/packages/core/framework/src/index.ts @@ -13,4 +13,4 @@ export * from "./telemetry" export const MEDUSA_CLI_PATH = require.resolve("@medusajs/medusa-cli") -export { GraphQLSchema, gqlSchemaToTypes, Query } from "@medusajs/modules-sdk" +export { Query } from "@medusajs/modules-sdk" diff --git a/packages/core/modules-sdk/package.json b/packages/core/modules-sdk/package.json index cdc491c0e4..3b7d6fc533 100644 --- a/packages/core/modules-sdk/package.json +++ b/packages/core/modules-sdk/package.json @@ -44,7 +44,6 @@ "@graphql-tools/schema": "^10.0.0", "@medusajs/orchestration": "^0.5.7", "@medusajs/utils": "^1.11.9", - "graphql": "^16.6.0", "resolve-cwd": "^3.0.0" }, "peerDependencies": { diff --git a/packages/core/modules-sdk/src/medusa-app.ts b/packages/core/modules-sdk/src/medusa-app.ts index 67c0c96751..f18d0fcc97 100644 --- a/packages/core/modules-sdk/src/medusa-app.ts +++ b/packages/core/modules-sdk/src/medusa-app.ts @@ -20,6 +20,7 @@ import { ContainerRegistrationKeys, createMedusaContainer, dynamicImport, + GraphQLUtils, isObject, isString, MedusaError, @@ -29,7 +30,6 @@ import { } from "@medusajs/utils" import type { Knex } from "@mikro-orm/knex" import { asValue } from "awilix" -import { GraphQLSchema } from "graphql/type" import { MODULE_PACKAGE_NAMES } from "./definitions" import { MedusaModule, @@ -39,7 +39,6 @@ import { import { RemoteLink } from "./remote-link" import { createQuery, RemoteQuery } from "./remote-query" import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types" -import { cleanGraphQLSchema } from "./utils" const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK] @@ -204,7 +203,7 @@ function cleanAndMergeSchema(loadedSchema) { scalar DateTime scalar JSON ` - const { schema: cleanedSchema, notFound } = cleanGraphQLSchema( + const { schema: cleanedSchema, notFound } = GraphQLUtils.cleanGraphQLSchema( defaultMedusaSchema + loadedSchema ) const mergedSchema = mergeTypeDefs(cleanedSchema) @@ -232,7 +231,7 @@ export type MedusaAppOutput = { link: RemoteLink | undefined query: RemoteQueryFunction entitiesMap?: Record - gqlSchema?: GraphQLSchema + gqlSchema?: GraphQLUtils.GraphQLSchema notFound?: Record> runMigrations: RunMigrationFn revertMigrations: RevertMigrationFn diff --git a/packages/core/modules-sdk/src/remote-query/__fixtures__/get-entities-map.ts b/packages/core/modules-sdk/src/remote-query/__fixtures__/get-entities-map.ts index 5a8ee322dd..df2c09e3f0 100644 --- a/packages/core/modules-sdk/src/remote-query/__fixtures__/get-entities-map.ts +++ b/packages/core/modules-sdk/src/remote-query/__fixtures__/get-entities-map.ts @@ -1,6 +1,6 @@ import { mergeTypeDefs } from "@graphql-tools/merge" import { makeExecutableSchema } from "@graphql-tools/schema" -import { cleanGraphQLSchema } from "../../utils/clean-graphql-schema" +import { cleanGraphQLSchema } from "@medusajs/utils" export function getEntitiesMap(loadedSchema): Map { const defaultMedusaSchema = ` diff --git a/packages/core/modules-sdk/src/types/index.ts b/packages/core/modules-sdk/src/types/index.ts index da8a679ee7..8f816756e5 100644 --- a/packages/core/modules-sdk/src/types/index.ts +++ b/packages/core/modules-sdk/src/types/index.ts @@ -7,5 +7,3 @@ export enum MODULE_RESOURCE_TYPE { SHARED = "shared", ISOLATED = "isolated", } - -export { GraphQLSchema } from "graphql" diff --git a/packages/core/modules-sdk/src/utils/index.ts b/packages/core/modules-sdk/src/utils/index.ts index 3426c3387a..2dbfa3a1cd 100644 --- a/packages/core/modules-sdk/src/utils/index.ts +++ b/packages/core/modules-sdk/src/utils/index.ts @@ -1,4 +1,2 @@ -export * from "./clean-graphql-schema" -export * from "./graphql-schema-to-fields" -export * from "./gql-schema-to-types" -export * from "./gql-get-fields-and-relations" +export * from "./linking-error" +export * from "./convert-data-to-link-definition" diff --git a/packages/core/orchestration/package.json b/packages/core/orchestration/package.json index 5f036c2024..3327941b57 100644 --- a/packages/core/orchestration/package.json +++ b/packages/core/orchestration/package.json @@ -33,8 +33,7 @@ "typescript": "^5.6.2" }, "dependencies": { - "@medusajs/utils": "^1.11.9", - "graphql": "^16.6.0" + "@medusajs/utils": "^1.11.9" }, "peerDependencies": { "awilix": "^8.0.1" diff --git a/packages/core/orchestration/src/joiner/remote-joiner.ts b/packages/core/orchestration/src/joiner/remote-joiner.ts index 63e610fa28..b75e03e898 100644 --- a/packages/core/orchestration/src/joiner/remote-joiner.ts +++ b/packages/core/orchestration/src/joiner/remote-joiner.ts @@ -10,12 +10,11 @@ import { } from "@medusajs/types" import { deduplicate, - extractRelationsFromGQL, + GraphQLUtils, isDefined, isString, MedusaError, } from "@medusajs/utils" -import GraphQLParser from "./graphql-ast" const BASE_PATH = "_root" @@ -140,7 +139,7 @@ export class RemoteJoiner { graphqlQuery: string, variables?: Record ): RemoteJoinerQuery { - const parser = new GraphQLParser(graphqlQuery, variables) + const parser = new GraphQLUtils.GraphQLParser(graphqlQuery, variables) return parser.parseQuery() } @@ -154,7 +153,9 @@ export class RemoteJoiner { ) { this.options.autoCreateServiceNameAlias ??= true if (this.options.entitiesMap) { - this.entityMap = extractRelationsFromGQL(this.options.entitiesMap) + this.entityMap = GraphQLUtils.extractRelationsFromGQL( + this.options.entitiesMap + ) } this.buildReferences( diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index f4a9830415..262dd29270 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -36,6 +36,8 @@ "typescript": "^5.6.2" }, "dependencies": { + "@graphql-tools/merge": "^9.0.7", + "@graphql-tools/schema": "^10.0.6", "@medusajs/types": "^1.11.16", "@mikro-orm/core": "5.9.7", "@mikro-orm/migrations": "5.9.7", diff --git a/packages/core/utils/src/bundles.ts b/packages/core/utils/src/bundles.ts index 650ed39213..0b639b7fa5 100644 --- a/packages/core/utils/src/bundles.ts +++ b/packages/core/utils/src/bundles.ts @@ -17,3 +17,4 @@ export * as PromotionUtils from "./promotion" export * as SearchUtils from "./search" export * as ShippingProfileUtils from "./shipping" export * as UserUtils from "./user" +export * as GraphQLUtils from "./graphql" diff --git a/packages/core/utils/src/common/index.ts b/packages/core/utils/src/common/index.ts index a9aa7e4d32..196d2cc625 100644 --- a/packages/core/utils/src/common/index.ts +++ b/packages/core/utils/src/common/index.ts @@ -26,7 +26,6 @@ export * from "./get-node-version" export * from "./get-selects-and-relations-from-object-array" export * from "./get-set-difference" export * from "./graceful-shutdown-server" -export * from "./graphql-relations-entity-map" export * from "./group-by" export * from "./handle-postgres-database-error" export * from "./is-big-number" diff --git a/packages/core/modules-sdk/src/__tests__/clean-graphql-schema.spec.ts b/packages/core/utils/src/graphql/__tests__/clean-graphql-schema.spec.ts similarity index 97% rename from packages/core/modules-sdk/src/__tests__/clean-graphql-schema.spec.ts rename to packages/core/utils/src/graphql/__tests__/clean-graphql-schema.spec.ts index 6b81140ac0..7c9c40a76a 100644 --- a/packages/core/modules-sdk/src/__tests__/clean-graphql-schema.spec.ts +++ b/packages/core/utils/src/graphql/__tests__/clean-graphql-schema.spec.ts @@ -1,4 +1,4 @@ -import { cleanGraphQLSchema } from "../utils/clean-graphql-schema" +import { cleanGraphQLSchema } from "../clean-graphql" describe("Clean Graphql Schema", function () { it("Should keep the schema intact if all entities are available", function () { diff --git a/packages/core/orchestration/src/__tests__/joiner/graphql-ast.ts b/packages/core/utils/src/graphql/__tests__/graphql-ast.ts similarity index 99% rename from packages/core/orchestration/src/__tests__/joiner/graphql-ast.ts rename to packages/core/utils/src/graphql/__tests__/graphql-ast.ts index 078d30229f..4e6d39f19e 100644 --- a/packages/core/orchestration/src/__tests__/joiner/graphql-ast.ts +++ b/packages/core/utils/src/graphql/__tests__/graphql-ast.ts @@ -1,4 +1,4 @@ -import GraphQLParser from "../../joiner/graphql-ast" +import { GraphQLParser } from "../graphql-parser" describe("RemoteJoiner.parseQuery", () => { beforeEach(() => { diff --git a/packages/core/modules-sdk/src/__tests__/utils/gql-get-fields-and-relations.spec.ts b/packages/core/utils/src/graphql/__tests__/utils/gql-get-fields-and-relations.spec.ts similarity index 96% rename from packages/core/modules-sdk/src/__tests__/utils/gql-get-fields-and-relations.spec.ts rename to packages/core/utils/src/graphql/__tests__/utils/gql-get-fields-and-relations.spec.ts index f76f35f3b3..7cd41153b5 100644 --- a/packages/core/modules-sdk/src/__tests__/utils/gql-get-fields-and-relations.spec.ts +++ b/packages/core/utils/src/graphql/__tests__/utils/gql-get-fields-and-relations.spec.ts @@ -1,6 +1,6 @@ import { mergeTypeDefs } from "@graphql-tools/merge" import { makeExecutableSchema } from "@graphql-tools/schema" -import { gqlGetFieldsAndRelations } from "../../utils" +import { gqlGetFieldsAndRelations } from "../../get-fields-and-relations" const userModule = ` type User { diff --git a/packages/core/modules-sdk/src/__tests__/utils/graphql-schema-to-fields.ts b/packages/core/utils/src/graphql/__tests__/utils/graphql-schema-to-fields.ts similarity index 97% rename from packages/core/modules-sdk/src/__tests__/utils/graphql-schema-to-fields.ts rename to packages/core/utils/src/graphql/__tests__/utils/graphql-schema-to-fields.ts index da14d6dd7b..2758895aae 100644 --- a/packages/core/modules-sdk/src/__tests__/utils/graphql-schema-to-fields.ts +++ b/packages/core/utils/src/graphql/__tests__/utils/graphql-schema-to-fields.ts @@ -1,6 +1,6 @@ import { mergeTypeDefs } from "@graphql-tools/merge" import { makeExecutableSchema } from "@graphql-tools/schema" -import { graphqlSchemaToFields } from "../../utils" +import { graphqlSchemaToFields } from "../../graphql-to-fields" const userModule = ` type User { diff --git a/packages/core/modules-sdk/src/utils/clean-graphql-schema.ts b/packages/core/utils/src/graphql/clean-graphql.ts similarity index 100% rename from packages/core/modules-sdk/src/utils/clean-graphql-schema.ts rename to packages/core/utils/src/graphql/clean-graphql.ts diff --git a/packages/core/utils/src/common/graphql-relations-entity-map.ts b/packages/core/utils/src/graphql/extract-relations-from-graphql.ts similarity index 100% rename from packages/core/utils/src/common/graphql-relations-entity-map.ts rename to packages/core/utils/src/graphql/extract-relations-from-graphql.ts diff --git a/packages/core/modules-sdk/src/utils/gql-get-fields-and-relations.ts b/packages/core/utils/src/graphql/get-fields-and-relations.ts similarity index 100% rename from packages/core/modules-sdk/src/utils/gql-get-fields-and-relations.ts rename to packages/core/utils/src/graphql/get-fields-and-relations.ts diff --git a/packages/core/orchestration/src/joiner/graphql-ast.ts b/packages/core/utils/src/graphql/graphql-parser.ts similarity index 98% rename from packages/core/orchestration/src/joiner/graphql-ast.ts rename to packages/core/utils/src/graphql/graphql-parser.ts index 8f32238ced..9998398d76 100644 --- a/packages/core/orchestration/src/joiner/graphql-ast.ts +++ b/packages/core/utils/src/graphql/graphql-parser.ts @@ -28,7 +28,10 @@ interface Entity { directives?: { [field: string]: Directive[] } } -class GraphQLParser { +/** + * Remote joiner graphql parser + */ +export class GraphQLParser { private ast: DocumentNode constructor(input: string, private variables: Record = {}) { @@ -190,5 +193,3 @@ class GraphQLParser { return remoteJoinConfig } } - -export default GraphQLParser diff --git a/packages/core/modules-sdk/src/utils/graphql-schema-to-fields.ts b/packages/core/utils/src/graphql/graphql-to-fields.ts similarity index 100% rename from packages/core/modules-sdk/src/utils/graphql-schema-to-fields.ts rename to packages/core/utils/src/graphql/graphql-to-fields.ts diff --git a/packages/core/modules-sdk/src/utils/gql-schema-to-types.ts b/packages/core/utils/src/graphql/graphql-to-ts-types.ts similarity index 84% rename from packages/core/modules-sdk/src/utils/gql-schema-to-types.ts rename to packages/core/utils/src/graphql/graphql-to-ts-types.ts index 675a4c8dbb..cfe14fb9a7 100644 --- a/packages/core/modules-sdk/src/utils/gql-schema-to-types.ts +++ b/packages/core/utils/src/graphql/graphql-to-ts-types.ts @@ -1,16 +1,19 @@ -import { MedusaModule } from "../medusa-module" import { FileSystem, toCamelCase } from "@medusajs/utils" import { GraphQLSchema } from "graphql/type" import { parse, printSchema } from "graphql" import { codegen } from "@graphql-codegen/core" import * as typescriptPlugin from "@graphql-codegen/typescript" +import { ModuleJoinerConfig } from "@medusajs/types" -function buildEntryPointsTypeMap( +function buildEntryPointsTypeMap({ + schema, + joinerConfigs, +}: { schema: string -): { entryPoint: string; entityType: any }[] { + joinerConfigs: ModuleJoinerConfig[] +}): { entryPoint: string; entityType: any }[] { // build map entry point to there type to be merged and used by the remote query - const joinerConfigs = MedusaModule.getAllJoinerConfigs() return joinerConfigs .flatMap((config) => { const aliases = Array.isArray(config.alias) @@ -41,15 +44,17 @@ async function generateTypes({ outputDir, filename, config, + joinerConfigs, }: { outputDir: string filename: string config: Parameters[0] + joinerConfigs: ModuleJoinerConfig[] }) { const fileSystem = new FileSystem(outputDir) let output = await codegen(config) - const entryPoints = buildEntryPointsTypeMap(output) + const entryPoints = buildEntryPointsTypeMap({ schema: output, joinerConfigs }) const interfaceName = toCamelCase(filename) @@ -81,14 +86,17 @@ ${entryPoints } } +// TODO: rename from gqlSchemaToTypes to grapthqlToTsTypes export async function gqlSchemaToTypes({ schema, outputDir, filename, + joinerConfigs, }: { schema: GraphQLSchema outputDir: string filename: string + joinerConfigs: ModuleJoinerConfig[] }) { const config = { documents: [], @@ -114,5 +122,5 @@ export async function gqlSchemaToTypes({ }, } - await generateTypes({ outputDir, filename, config }) + await generateTypes({ outputDir, filename, config, joinerConfigs }) } diff --git a/packages/core/utils/src/graphql/index.ts b/packages/core/utils/src/graphql/index.ts new file mode 100644 index 0000000000..976efb0bb1 --- /dev/null +++ b/packages/core/utils/src/graphql/index.ts @@ -0,0 +1,9 @@ +export * from "./graphql-parser" +export * from "./graphql-to-fields" +export * from "./extract-relations-from-graphql" +export * from "./clean-graphql" +export * from "./graphql-to-ts-types" +export * from "./get-fields-and-relations" + +export * from "graphql" +export * from "graphql/type" diff --git a/packages/core/utils/src/index.ts b/packages/core/utils/src/index.ts index 071f297dd1..e6071edda8 100644 --- a/packages/core/utils/src/index.ts +++ b/packages/core/utils/src/index.ts @@ -1,3 +1,4 @@ +export * from "./graphql" export * from "./api-key" export * from "./auth" export * from "./bundles" diff --git a/packages/medusa/src/commands/start.ts b/packages/medusa/src/commands/start.ts index 014bdcde67..6b1c0dc6a9 100644 --- a/packages/medusa/src/commands/start.ts +++ b/packages/medusa/src/commands/start.ts @@ -3,11 +3,12 @@ import express from "express" import { track } from "medusa-telemetry" import { scheduleJob } from "node-schedule" -import { GracefulShutdownServer } from "@medusajs/utils" +import { gqlSchemaToTypes, GracefulShutdownServer } from "@medusajs/utils" import http, { IncomingMessage, ServerResponse } from "http" -import { gqlSchemaToTypes, logger } from "@medusajs/framework" +import { logger } from "@medusajs/framework" import loaders from "../loaders" +import { MedusaModule } from "@medusajs/modules-sdk" const EVERY_SIXTH_HOUR = "0 */6 * * *" const CRON_SCHEDULE = EVERY_SIXTH_HOUR @@ -66,6 +67,7 @@ async function start({ port, directory, types }) { outputDir: outputDirGeneratedTypes, filename: "remote-query-entry-points", schema: gqlSchema, + joinerConfigs: MedusaModule.getAllJoinerConfigs(), }) logger.info("Geneated modules types") } diff --git a/packages/medusa/src/loaders/index.ts b/packages/medusa/src/loaders/index.ts index e02e068b9f..3c963ce815 100644 --- a/packages/medusa/src/loaders/index.ts +++ b/packages/medusa/src/loaders/index.ts @@ -1,5 +1,5 @@ import { ConfigModule, MedusaContainer, PluginDetails } from "@medusajs/types" -import { ContainerRegistrationKeys, promiseAll } from "@medusajs/utils" +import { ContainerRegistrationKeys, promiseAll, GraphQLSchema } from "@medusajs/utils" import { asValue } from "awilix" import { Express, NextFunction, Request, Response } from "express" import { join } from "path" @@ -12,7 +12,6 @@ import { container, expressLoader, featureFlagsLoader, - GraphQLSchema, JobLoader, LinkLoader, logger, diff --git a/packages/modules/index/src/utils/build-config.ts b/packages/modules/index/src/utils/build-config.ts index 369b7955d0..9aa71491ee 100644 --- a/packages/modules/index/src/utils/build-config.ts +++ b/packages/modules/index/src/utils/build-config.ts @@ -1,18 +1,13 @@ import { makeExecutableSchema } from "@graphql-tools/schema" -import { - cleanGraphQLSchema, - gqlGetFieldsAndRelations, - MedusaModule, -} from "@medusajs/modules-sdk" +import { MedusaModule } from "@medusajs/modules-sdk" import { IndexTypes, JoinerServiceConfigAlias, ModuleJoinerConfig, ModuleJoinerRelationship, } from "@medusajs/types" -import { CommonEvents } from "@medusajs/utils" +import { CommonEvents, GraphQLUtils } from "@medusajs/utils" import { schemaObjectRepresentationPropertiesToOmit } from "@types" -import { Kind, ObjectTypeDefinitionNode } from "graphql/index" export const CustomDirectives = { Listeners: { @@ -25,7 +20,7 @@ export const CustomDirectives = { } export function makeSchemaExecutable(inputSchema: string) { - const { schema: cleanedSchema } = cleanGraphQLSchema(inputSchema) + const { schema: cleanedSchema } = GraphQLUtils.cleanGraphQLSchema(inputSchema) return makeExecutableSchema({ typeDefs: cleanedSchema }) } @@ -330,7 +325,7 @@ function processEntity( ) currentObjectRepresentationRef.fields = - gqlGetFieldsAndRelations(entitiesMap, entityName) ?? [] + GraphQLUtils.gqlGetFieldsAndRelations(entitiesMap, entityName) ?? [] /** * Retrieve the module and alias for the current entity. @@ -372,14 +367,16 @@ function processEntity( const schemaParentEntity = Object.values(entitiesMap).filter((value: any) => { return ( value.astNode && - (value.astNode as ObjectTypeDefinitionNode).fields?.some((field: any) => { - let currentType = field.type - while (currentType.type) { - currentType = currentType.type - } + (value.astNode as GraphQLUtils.ObjectTypeDefinitionNode).fields?.some( + (field: any) => { + let currentType = field.type + while (currentType.type) { + currentType = currentType.type + } - return currentType.name?.value === entityName - }) + return currentType.name?.value === entityName + } + ) ) }) @@ -410,7 +407,7 @@ function processEntity( }) const isEntityListInParent = - entityFieldInParent.type.kind === Kind.LIST_TYPE + entityFieldInParent.type.kind === GraphQLUtils.Kind.LIST_TYPE const entityTargetPropertyNameInParent = entityFieldInParent.name.value /** diff --git a/packages/modules/index/src/utils/gql-to-types.ts b/packages/modules/index/src/utils/gql-to-types.ts index 51f996d0cd..ae37c0723a 100644 --- a/packages/modules/index/src/utils/gql-to-types.ts +++ b/packages/modules/index/src/utils/gql-to-types.ts @@ -1,10 +1,9 @@ import { join } from "path" import { CustomDirectives, makeSchemaExecutable } from "./build-config" import { - gqlSchemaToTypes as ModulesSdkGqlSchemaToTypes, MedusaModule, } from "@medusajs/modules-sdk" -import { FileSystem } from "@medusajs/utils" +import { FileSystem, gqlSchemaToTypes as ModulesSdkGqlSchemaToTypes, } from "@medusajs/utils" import * as process from "process" export async function gqlSchemaToTypes(schema: string) { @@ -18,6 +17,7 @@ export async function gqlSchemaToTypes(schema: string) { schema: executableSchema, filename, outputDir: dir, + joinerConfigs: MedusaModule.getAllJoinerConfigs(), }) const fileSystem = new FileSystem(dir) diff --git a/yarn.lock b/yarn.lock index c094698fb6..86db165a92 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4535,7 +4535,7 @@ __metadata: languageName: node linkType: hard -"@graphql-tools/merge@npm:^9.0.6": +"@graphql-tools/merge@npm:^9.0.6, @graphql-tools/merge@npm:^9.0.7": version: 9.0.7 resolution: "@graphql-tools/merge@npm:9.0.7" dependencies: @@ -4611,7 +4611,7 @@ __metadata: languageName: node linkType: hard -"@graphql-tools/schema@npm:^10.0.3, @graphql-tools/schema@npm:^10.0.4": +"@graphql-tools/schema@npm:^10.0.3, @graphql-tools/schema@npm:^10.0.4, @graphql-tools/schema@npm:^10.0.6": version: 10.0.6 resolution: "@graphql-tools/schema@npm:10.0.6" dependencies: @@ -6249,7 +6249,6 @@ __metadata: "@medusajs/types": ^1.11.16 "@medusajs/utils": ^1.11.9 cross-env: ^5.2.1 - graphql: ^16.6.0 jest: ^29.7.0 resolve-cwd: ^3.0.0 rimraf: ^5.0.1 @@ -6326,7 +6325,6 @@ __metadata: "@medusajs/types": ^1.11.16 "@medusajs/utils": ^1.11.9 cross-env: ^5.2.1 - graphql: ^16.6.0 jest: ^29.7.0 rimraf: ^5.0.1 typescript: ^5.6.2 @@ -6741,6 +6739,8 @@ __metadata: version: 0.0.0-use.local resolution: "@medusajs/utils@workspace:packages/core/utils" dependencies: + "@graphql-tools/merge": ^9.0.7 + "@graphql-tools/schema": ^10.0.6 "@medusajs/types": ^1.11.16 "@mikro-orm/core": 5.9.7 "@mikro-orm/migrations": 5.9.7 @@ -21410,7 +21410,7 @@ __metadata: languageName: node linkType: hard -"graphql@npm:^16.6.0, graphql@npm:^16.8.1": +"graphql@npm:^16.8.1": version: 16.8.1 resolution: "graphql@npm:16.8.1" checksum: 129c318156b466f440914de80dbf7bc67d17f776f2a088a40cb0da611d19a97c224b1c6d2b13cbcbc6e5776e45ed7468b8432f9c3536724e079b44f1a3d57a8a