Skip to content

Commit

Permalink
Merge branch 'master' into feat/nestjs-connectrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisAnubiz committed Nov 5, 2024
2 parents 92da2f4 + 3f4cb0b commit 0c3ce79
Show file tree
Hide file tree
Showing 9 changed files with 2,909 additions and 1,436 deletions.
2,552 changes: 1,731 additions & 821 deletions .pnp.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/nestjs-gateway/integration/test/gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('gateway', () => {
})
.compile()

app = testingModule.createNestApplication() as INestApplication
app = testingModule.createNestApplication()

service = testingModule.createNestMicroservice({
transport: Transport.GRPC,
Expand Down
59 changes: 30 additions & 29 deletions packages/nestjs-gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atls/nestjs-gateway",
"version": "0.0.11",
"version": "0.0.13",
"license": "BSD 3-Clause",
"type": "module",
"exports": {
Expand All @@ -16,46 +16,47 @@
"postpack": "rm -rf dist"
},
"dependencies": {
"@atls/grpc-error-status": "0.0.3",
"@atls/grpc-error-status": "0.1.5",
"@atls/logger": "0.0.2",
"@graphql-mesh/cache-inmemory-lru": "0.5.59",
"@graphql-mesh/cache-inmemory-lru": "0.6.18",
"@graphql-mesh/config": "0.19.8",
"@graphql-mesh/merger-stitching": "0.10.8",
"@graphql-mesh/cross-helpers": "0.4.7",
"@graphql-mesh/merger-stitching": "0.102.11",
"@graphql-mesh/runtime": "0.18.7",
"@graphql-mesh/store": "0.1.19",
"@graphql-mesh/transform-cache": "0.9.21",
"@graphql-mesh/transform-encapsulate": "0.1.67",
"@graphql-mesh/transform-filter-schema": "0.10.28",
"@graphql-mesh/transform-mock": "0.10.21",
"@graphql-mesh/transform-naming-convention": "0.6.69",
"@graphql-mesh/transform-prefix": "0.6.59",
"@graphql-mesh/transform-rename": "0.9.18",
"@graphql-mesh/transform-resolvers-composition": "0.10.19",
"@graphql-mesh/transform-snapshot": "0.10.20",
"@graphql-mesh/types": "0.45.2",
"@graphql-mesh/utils": "0.13.7",
"@graphql-tools/utils": "8.13.1",
"@grpc/grpc-js": "1.11.2",
"@graphql-mesh/store": "0.102.11",
"@graphql-mesh/transform-cache": "0.102.11",
"@graphql-mesh/transform-encapsulate": "0.102.11",
"@graphql-mesh/transform-filter-schema": "0.102.11",
"@graphql-mesh/transform-mock": "0.15.6",
"@graphql-mesh/transform-naming-convention": "0.102.11",
"@graphql-mesh/transform-prefix": "0.102.11",
"@graphql-mesh/transform-rename": "0.102.11",
"@graphql-mesh/transform-resolvers-composition": "0.102.11",
"@graphql-mesh/transform-snapshot": "0.14.65",
"@graphql-mesh/types": "0.102.11",
"@graphql-mesh/utils": "0.102.11",
"@graphql-tools/utils": "10.5.5",
"@grpc/grpc-js": "1.12.2",
"@grpc/proto-loader": "0.7.13",
"@types/long": "4.0.2",
"apollo-server-express": "2.26.2",
"globby": "11.0.4",
"globby": "14.0.2",
"graphql-compose": "9.0.11",
"graphql-scalars": "1.23.0",
"graphql-subscriptions": "1.2.1",
"graphql-subscriptions": "2.0.0",
"graphql-ws": "5.16.0",
"lodash": "4.17.21",
"long": "4.0.0",
"protobufjs": "7.4.0"
"long": "5.2.3",
"protobufjs": "7.4.0",
"tslib": "2.8.0"
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@nestjs/common": "10.4.1",
"@nestjs/core": "10.4.1",
"@nestjs/microservices": "10.4.1",
"@nestjs/testing": "10.4.1",
"@types/lodash": "4.17.7",
"@types/node": "22.5.5",
"@nestjs/common": "10.4.6",
"@nestjs/core": "10.4.6",
"@nestjs/microservices": "10.4.6",
"@nestjs/testing": "10.4.6",
"@types/lodash": "4.17.13",
"@types/node": "22.8.5",
"@types/supertest": "6.0.2",
"@types/ws": "8.5.12",
"get-port": "7.1.0",
Expand Down
68 changes: 21 additions & 47 deletions packages/nestjs-gateway/src/mesh/graphql-mesh.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,33 @@

// @ts-expect-error
import type { GetMeshOptions } from '@graphql-mesh/runtime'
// @ts-expect-error
import type { MeshTransform } from '@graphql-mesh/types'
import type { MeshPubSub } from '@graphql-mesh/types'
import type { ImportFn } from '@graphql-mesh/types'

import type { SourceOptions } from '../module/index.js'
import type { SourceTransformsOptions } from '../module/index.js'

// @ts-expect-error
import { InMemoryStoreStorageAdapter } from '@graphql-mesh/store'
// @ts-expect-error
import { MeshStore } from '@graphql-mesh/store'
import { Inject } from '@nestjs/common'
import { Injectable } from '@nestjs/common'
// @ts-expect-error
import { resolveAdditionalTypeDefs } from '@graphql-mesh/config'
// @ts-expect-error
import { getDefaultSyncImport } from '@graphql-mesh/utils'
// @ts-expect-error
import { resolveAdditionalResolvers } from '@graphql-mesh/utils'
// @ts-expect-error
import InMemoryLRUCache from '@graphql-mesh/cache-inmemory-lru'
// @ts-expect-error
import StitchingMerger from '@graphql-mesh/merger-stitching'
// @ts-expect-error
import CacheTransform from '@graphql-mesh/transform-cache'
// @ts-expect-error
import EncapsulateTransform from '@graphql-mesh/transform-encapsulate'
// @ts-expect-error
import FilterTransform from '@graphql-mesh/transform-filter-schema'
// @ts-expect-error
import MockingTransform from '@graphql-mesh/transform-mock'
// @ts-expect-error
import NamingConventionTransform from '@graphql-mesh/transform-naming-convention'
// @ts-expect-error
import PrefixTransform from '@graphql-mesh/transform-prefix'
// @ts-expect-error
import RenameTransform from '@graphql-mesh/transform-rename'
// @ts-expect-error
import ResolversCompositionTransform from '@graphql-mesh/transform-resolvers-composition'
// @ts-expect-error
import SnapshotTransform from '@graphql-mesh/transform-snapshot'
Expand Down Expand Up @@ -76,7 +66,6 @@ export class GraphQLMeshConfig {
this.baseDir = process.cwd()
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.cache = options.cache || new InMemoryLRUCache()
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.store = new MeshStore(join(process.cwd(), '.mesh'), new InMemoryStoreStorageAdapter(), {
readonly: false,
validate: false,
Expand All @@ -88,11 +77,9 @@ export class GraphQLMeshConfig {

this.merger =
options.merger ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new StitchingMerger({
cache: this.cache,
pubsub: this.pubsub,
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
pubsub: this.pubsub as unknown as MeshPubSub,
store: this.store.child(`StitchingMerger`),
logger: this.logger,
})
Expand All @@ -104,12 +91,11 @@ export class GraphQLMeshConfig {
this.baseDir,
this.options.additionalTypeDefs
)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const additionalResolvers = await resolveAdditionalResolvers(
this.baseDir,
this.options.additionalResolvers || [],
this.syncImportFn,
this.pubsub
this.syncImportFn as ImportFn,
this.pubsub as unknown as MeshPubSub
)

return {
Expand Down Expand Up @@ -159,70 +145,58 @@ export class GraphQLMeshConfig {

if (config.rename) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new RenameTransform({
apiName,
syncImportFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.rename,
cache: this.cache,
pubsub: this.pubsub,
})
)
}

if (config.filterSchema) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
FilterTransform({
apiName,
syncImportFn: this.syncImportFn,
baseDir: this.baseDir,
new FilterTransform({
config: config.filterSchema,
cache: this.cache,
pubsub: this.pubsub,
})
)
}

if (config.encapsulate) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new EncapsulateTransform({
apiName,
syncImportFn: this.syncImportFn,
importFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.encapsulate,
cache: this.cache,
pubsub: this.pubsub,
pubsub: this.pubsub as unknown as MeshPubSub,
logger: this.logger,
})
)
}

if (config.prefix) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new PrefixTransform({
apiName,
syncImportFn: this.syncImportFn,
importFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.prefix,
cache: this.cache,
pubsub: this.pubsub,
pubsub: this.pubsub as unknown as MeshPubSub,
logger: this.logger,
})
)
}

if (config.cache) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new CacheTransform({
apiName,
syncImportFn: this.syncImportFn,
importFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.cache,
cache: this.cache,
pubsub: this.pubsub,
pubsub: this.pubsub as unknown as MeshPubSub,
logger: this.logger,
})
)
}
Expand Down Expand Up @@ -257,28 +231,28 @@ export class GraphQLMeshConfig {

if (config.resolversComposition) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new ResolversCompositionTransform({
apiName,
syncImportFn: this.syncImportFn,
importFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.resolversComposition,
cache: this.cache,
pubsub: this.pubsub,
pubsub: this.pubsub as unknown as MeshPubSub,
logger: this.logger,
})
)
}

if (config.namingConvention) {
transforms.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new NamingConventionTransform({
apiName,
syncImportFn: this.syncImportFn,
importFn: this.syncImportFn,
baseDir: this.baseDir,
config: config.namingConvention,
cache: this.cache,
pubsub: this.pubsub,
pubsub: this.pubsub as unknown as MeshPubSub,
logger: this.logger,
})
)
}
Expand Down
1 change: 0 additions & 1 deletion packages/nestjs-gateway/src/mesh/graphql-mesh.logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-expect-error
import type { Logger as MeshLogger } from '@graphql-mesh/types'

import { Logger } from '@atls/logger'
Expand Down
13 changes: 12 additions & 1 deletion packages/nestjs-gateway/src/mesh/handlers/grpc/grpc.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import { Message } from 'protobufjs'
import { Constructor } from 'protobufjs'
import { IFileDescriptorSet } from 'protobufjs/ext/descriptor'
import { promises as fsPromises } from 'fs'
import { globby } from 'globby'
import { specifiedDirectives } from 'graphql'
import { isAbsolute } from 'path'
import { join } from 'path'
import { promisify } from 'util'
import _ from 'lodash'
import globby from 'globby'
import protobufjs from 'protobufjs'
import descriptor from 'protobufjs/ext/descriptor/index.js'

Expand Down Expand Up @@ -113,12 +113,16 @@ module.exports = {
}
}
}
// @ts-expect-error
if (this.config.descriptorSetFilePath) {
let fileName: string
let options: LoadOptions
// @ts-expect-error
if (typeof this.config.descriptorSetFilePath === 'object') {
// @ts-expect-error
fileName = this.config.descriptorSetFilePath.file
options = {
// @ts-expect-error
...this.config.descriptorSetFilePath.load,
// @ts-ignore
includeDirs: this.config.descriptorSetFilePath.load.includeDirs?.map((includeDir) =>
Expand All @@ -131,6 +135,7 @@ module.exports = {
addIncludePathResolver(root, options.includeDirs)
}
} else {
// @ts-expect-error
fileName = this.config.descriptorSetFilePath
}
const absoluteFilePath = isAbsolute(fileName) ? fileName : join(this.baseDir, fileName)
Expand All @@ -151,13 +156,17 @@ module.exports = {
appendRoot(rootFromDescriptor)
}

// @ts-expect-error
if (this.config.protoFilePath) {
let protoRoot = new Root()
let fileGlob: string
let options: LoadOptions = {}
// @ts-expect-error
if (typeof this.config.protoFilePath === 'object') {
// @ts-expect-error
fileGlob = this.config.protoFilePath.file
options = {
// @ts-expect-error
...this.config.protoFilePath.load,
// @ts-ignore
includeDirs: this.config.protoFilePath.load.includeDirs?.map((includeDir) =>
Expand All @@ -170,6 +179,7 @@ module.exports = {
addIncludePathResolver(protoRoot, options.includeDirs)
}
} else {
// @ts-expect-error
fileGlob = this.config.protoFilePath
}

Expand Down Expand Up @@ -385,6 +395,7 @@ module.exports = {
},
}
if (method.responseStream) {
// @ts-expect-error
const clientMethod: ClientMethod = (input: unknown = {}, metaData?: Metadata) => {
const responseStream = client[methodName](
input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @ts-expect-error
import type { MeshPubSub } from '@graphql-mesh/types'
// @ts-expect-error
import type { KeyValueCache } from '@graphql-mesh/types'
// @ts-expect-error
import type { MeshMerger } from '@graphql-mesh/types'
// @ts-expect-error
import type { YamlConfig } from '@graphql-mesh/types'
import type { ChannelOptions } from '@grpc/grpc-js'
import type { ModuleMetadata } from '@nestjs/common/interfaces'
Expand Down Expand Up @@ -47,11 +43,8 @@ export interface GatewayModuleOptions {
limit?: number | string
grpcChannelOptions?: Partial<ChannelOptions>
additionalResolvers?: Array<
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| YamlConfig.AdditionalStitchingBatchResolverObject
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| YamlConfig.AdditionalStitchingResolverObject
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
| YamlConfig.AdditionalSubscriptionObject
| string
>
Expand Down
Loading

0 comments on commit 0c3ce79

Please sign in to comment.