chore: remove direct usage from graphql (#9316)

**What**
Remove direct usage of graphql toold and instead consume it from utils to have a single entry point to graphql tooling
This commit is contained in:
Adrien de Peretti
2024-09-26 10:18:26 +02:00
committed by GitHub
parent f294c99c92
commit fba78c0fb1
7 changed files with 84 additions and 1003 deletions

View File

@@ -1,5 +1,3 @@
import { mergeTypeDefs } from "@graphql-tools/merge"
import { makeExecutableSchema } from "@graphql-tools/schema"
import { RemoteFetchDataCallback } from "@medusajs/orchestration"
import {
ConfigModule,
@@ -18,14 +16,14 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
createMedusaContainer,
dynamicImport,
GraphQLUtils,
isObject,
isString,
MedusaError,
Modules,
ModulesSdkUtils,
createMedusaContainer,
dynamicImport,
isObject,
isString,
promiseAll,
} from "@medusajs/utils"
import type { Knex } from "@mikro-orm/knex"
@@ -37,7 +35,7 @@ import {
RegisterModuleJoinerConfig,
} from "./medusa-module"
import { RemoteLink } from "./remote-link"
import { RemoteQuery, createQuery } from "./remote-query"
import { createQuery, RemoteQuery } from "./remote-query"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK]
@@ -228,8 +226,11 @@ function cleanAndMergeSchema(loadedSchema) {
const { schema: cleanedSchema, notFound } = GraphQLUtils.cleanGraphQLSchema(
defaultMedusaSchema + loadedSchema
)
const mergedSchema = mergeTypeDefs(cleanedSchema)
return { schema: makeExecutableSchema({ typeDefs: mergedSchema }), notFound }
const mergedSchema = GraphQLUtils.mergeTypeDefs(cleanedSchema)
return {
schema: GraphQLUtils.makeExecutableSchema({ typeDefs: mergedSchema }),
notFound,
}
}
function getLoadedSchema(): string {

View File

@@ -1,13 +1,15 @@
import { mergeTypeDefs } from "@graphql-tools/merge"
import { makeExecutableSchema } from "@graphql-tools/schema"
import { cleanGraphQLSchema } from "@medusajs/utils"
import { GraphQLUtils } from "@medusajs/utils"
export function getEntitiesMap(loadedSchema): Map<string, any> {
const defaultMedusaSchema = `
scalar DateTime
scalar JSON
`
const { schema } = cleanGraphQLSchema(defaultMedusaSchema + loadedSchema)
const mergedSchema = mergeTypeDefs(schema)
return makeExecutableSchema({ typeDefs: mergedSchema }).getTypeMap() as any
const { schema } = GraphQLUtils.cleanGraphQLSchema(
defaultMedusaSchema + loadedSchema
)
const mergedSchema = GraphQLUtils.mergeTypeDefs(schema)
return GraphQLUtils.makeExecutableSchema({
typeDefs: mergedSchema,
}).getTypeMap() as any
}