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:
@@ -32,16 +32,14 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@medusajs/types": "^1.11.16",
|
"@medusajs/types": "^1.11.16",
|
||||||
|
"@mikro-orm/core": "5.9.7",
|
||||||
|
"awilix": "^8.0.1",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"rimraf": "^5.0.1",
|
"rimraf": "^5.0.1",
|
||||||
"typescript": "^5.6.2"
|
"typescript": "^5.6.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@graphql-codegen/cli": "^5.0.2",
|
|
||||||
"@graphql-codegen/typescript": "^4.0.9",
|
|
||||||
"@graphql-tools/merge": "^9.0.0",
|
|
||||||
"@graphql-tools/schema": "^10.0.0",
|
|
||||||
"@medusajs/orchestration": "^0.5.7",
|
"@medusajs/orchestration": "^0.5.7",
|
||||||
"@medusajs/utils": "^1.11.9",
|
"@medusajs/utils": "^1.11.9",
|
||||||
"resolve-cwd": "^3.0.0"
|
"resolve-cwd": "^3.0.0"
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { mergeTypeDefs } from "@graphql-tools/merge"
|
|
||||||
import { makeExecutableSchema } from "@graphql-tools/schema"
|
|
||||||
import { RemoteFetchDataCallback } from "@medusajs/orchestration"
|
import { RemoteFetchDataCallback } from "@medusajs/orchestration"
|
||||||
import {
|
import {
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
@@ -18,14 +16,14 @@ import {
|
|||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
|
createMedusaContainer,
|
||||||
|
dynamicImport,
|
||||||
GraphQLUtils,
|
GraphQLUtils,
|
||||||
|
isObject,
|
||||||
|
isString,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
Modules,
|
Modules,
|
||||||
ModulesSdkUtils,
|
ModulesSdkUtils,
|
||||||
createMedusaContainer,
|
|
||||||
dynamicImport,
|
|
||||||
isObject,
|
|
||||||
isString,
|
|
||||||
promiseAll,
|
promiseAll,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import type { Knex } from "@mikro-orm/knex"
|
import type { Knex } from "@mikro-orm/knex"
|
||||||
@@ -37,7 +35,7 @@ import {
|
|||||||
RegisterModuleJoinerConfig,
|
RegisterModuleJoinerConfig,
|
||||||
} from "./medusa-module"
|
} from "./medusa-module"
|
||||||
import { RemoteLink } from "./remote-link"
|
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"
|
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||||
|
|
||||||
const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK]
|
const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK]
|
||||||
@@ -228,8 +226,11 @@ function cleanAndMergeSchema(loadedSchema) {
|
|||||||
const { schema: cleanedSchema, notFound } = GraphQLUtils.cleanGraphQLSchema(
|
const { schema: cleanedSchema, notFound } = GraphQLUtils.cleanGraphQLSchema(
|
||||||
defaultMedusaSchema + loadedSchema
|
defaultMedusaSchema + loadedSchema
|
||||||
)
|
)
|
||||||
const mergedSchema = mergeTypeDefs(cleanedSchema)
|
const mergedSchema = GraphQLUtils.mergeTypeDefs(cleanedSchema)
|
||||||
return { schema: makeExecutableSchema({ typeDefs: mergedSchema }), notFound }
|
return {
|
||||||
|
schema: GraphQLUtils.makeExecutableSchema({ typeDefs: mergedSchema }),
|
||||||
|
notFound,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLoadedSchema(): string {
|
function getLoadedSchema(): string {
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { mergeTypeDefs } from "@graphql-tools/merge"
|
import { GraphQLUtils } from "@medusajs/utils"
|
||||||
import { makeExecutableSchema } from "@graphql-tools/schema"
|
|
||||||
import { cleanGraphQLSchema } from "@medusajs/utils"
|
|
||||||
|
|
||||||
export function getEntitiesMap(loadedSchema): Map<string, any> {
|
export function getEntitiesMap(loadedSchema): Map<string, any> {
|
||||||
const defaultMedusaSchema = `
|
const defaultMedusaSchema = `
|
||||||
scalar DateTime
|
scalar DateTime
|
||||||
scalar JSON
|
scalar JSON
|
||||||
`
|
`
|
||||||
const { schema } = cleanGraphQLSchema(defaultMedusaSchema + loadedSchema)
|
const { schema } = GraphQLUtils.cleanGraphQLSchema(
|
||||||
const mergedSchema = mergeTypeDefs(schema)
|
defaultMedusaSchema + loadedSchema
|
||||||
return makeExecutableSchema({ typeDefs: mergedSchema }).getTypeMap() as any
|
)
|
||||||
|
const mergedSchema = GraphQLUtils.mergeTypeDefs(schema)
|
||||||
|
return GraphQLUtils.makeExecutableSchema({
|
||||||
|
typeDefs: mergedSchema,
|
||||||
|
}).getTypeMap() as any
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ export * from "./get-fields-and-relations"
|
|||||||
|
|
||||||
export * from "graphql"
|
export * from "graphql"
|
||||||
export * from "graphql/type"
|
export * from "graphql/type"
|
||||||
|
export { makeExecutableSchema } from "@graphql-tools/schema"
|
||||||
|
export { mergeTypeDefs } from "@graphql-tools/merge"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { makeExecutableSchema } from "@graphql-tools/schema"
|
|
||||||
import { MedusaModule } from "@medusajs/framework/modules-sdk"
|
import { MedusaModule } from "@medusajs/framework/modules-sdk"
|
||||||
import {
|
import {
|
||||||
IndexTypes,
|
IndexTypes,
|
||||||
@@ -22,7 +21,7 @@ export const CustomDirectives = {
|
|||||||
export function makeSchemaExecutable(inputSchema: string) {
|
export function makeSchemaExecutable(inputSchema: string) {
|
||||||
const { schema: cleanedSchema } = GraphQLUtils.cleanGraphQLSchema(inputSchema)
|
const { schema: cleanedSchema } = GraphQLUtils.cleanGraphQLSchema(inputSchema)
|
||||||
|
|
||||||
return makeExecutableSchema({ typeDefs: cleanedSchema })
|
return GraphQLUtils.makeExecutableSchema({ typeDefs: cleanedSchema })
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractNameFromAlias(
|
function extractNameFromAlias(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { isObject, isString } from "@medusajs/framework/utils"
|
import { isObject, isString, GraphQLUtils } from "@medusajs/utils"
|
||||||
import { IndexTypes } from "@medusajs/framework/types"
|
import { IndexTypes } from "@medusajs/framework/types"
|
||||||
import { GraphQLList } from "graphql"
|
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
import { OrderBy, QueryFormat, QueryOptions, Select } from "@types"
|
import { OrderBy, QueryFormat, QueryOptions, Select } from "@types"
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ export class QueryBuilder {
|
|||||||
let currentType = fieldRef.type
|
let currentType = fieldRef.type
|
||||||
let isArray = false
|
let isArray = false
|
||||||
while (currentType.ofType) {
|
while (currentType.ofType) {
|
||||||
if (currentType instanceof GraphQLList) {
|
if (currentType instanceof GraphQLUtils.GraphQLList) {
|
||||||
isArray = true
|
isArray = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user