nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -1196
- package/dist/cli/adapter.d.mts +13 -0
- package/dist/cli/adapter.mjs +69 -0
- package/dist/cli/commands/build.d.mts +21 -0
- package/dist/cli/commands/build.mjs +52 -0
- package/dist/cli/commands/dev.d.mts +40 -0
- package/dist/cli/commands/dev.mjs +76 -0
- package/dist/cli/commands/generate.d.mts +25 -0
- package/dist/cli/commands/generate.mjs +198 -0
- package/dist/cli/commands/index.d.mts +5 -0
- package/dist/cli/commands/index.mjs +6 -0
- package/dist/cli/commands/init.d.mts +45 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +9 -0
- package/dist/cli/commands/validate.mjs +67 -0
- package/dist/cli/completions.d.mts +6 -0
- package/dist/cli/completions.mjs +34 -0
- package/dist/cli/config.d.mts +18 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +26 -0
- package/dist/cli/index.mjs +317 -0
- package/dist/cli/server/debug-handler.d.mts +9 -0
- package/dist/cli/server/debug-handler.mjs +71 -0
- package/dist/cli/server/dev-server.d.mts +29 -0
- package/dist/cli/server/dev-server.mjs +64 -0
- package/dist/cli/server/graphql-handler.d.mts +21 -0
- package/dist/cli/server/graphql-handler.mjs +45 -0
- package/dist/cli/server/health-handler.d.mts +12 -0
- package/dist/cli/server/health-handler.mjs +30 -0
- package/dist/cli/server/loader.d.mts +33 -0
- package/dist/cli/server/loader.mjs +146 -0
- package/dist/cli/server/sandbox-handler.d.mts +12 -0
- package/dist/cli/server/sandbox-handler.mjs +19 -0
- package/dist/cli/server/watcher.d.mts +20 -0
- package/dist/cli/server/watcher.mjs +66 -0
- package/dist/cli/server/ws-handler.d.mts +28 -0
- package/dist/cli/server/ws-handler.mjs +50 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +3 -0
- package/dist/core/codegen/client.d.mts +42 -0
- package/dist/core/codegen/client.mjs +553 -0
- package/dist/core/codegen/document-loader.d.mts +9 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/core/codegen/plugin.d.mts +19 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- package/dist/core/codegen/runtime.d.mts +19 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +27 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +27 -0
- package/dist/core/codegen/server.mjs +144 -0
- package/dist/core/codegen/validation.d.mts +17 -0
- package/dist/core/codegen/validation.mjs +35 -0
- package/dist/core/config.d.mts +45 -0
- package/dist/core/config.mjs +78 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/debug/index.d.mts +2 -0
- package/dist/core/debug/index.mjs +3 -0
- package/dist/core/debug/template.d.mts +52 -0
- package/dist/core/debug/template.mjs +383 -0
- package/dist/core/extend/index.d.mts +2 -0
- package/dist/core/extend/index.mjs +3 -0
- package/dist/core/extend/loader.d.mts +40 -0
- package/dist/core/extend/loader.mjs +198 -0
- package/dist/core/index.d.mts +37 -0
- package/dist/core/index.mjs +29 -0
- package/dist/core/manifest.d.mts +56 -0
- package/dist/core/manifest.mjs +102 -0
- package/dist/core/pubsub/index.d.mts +109 -0
- package/dist/core/pubsub/index.mjs +148 -0
- package/dist/core/scanning/ast-scanner.d.mts +27 -0
- package/dist/core/scanning/ast-scanner.mjs +116 -0
- package/dist/core/scanning/common.d.mts +25 -0
- package/dist/core/scanning/common.mjs +59 -0
- package/dist/core/scanning/directives.d.mts +13 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +20 -0
- package/dist/core/scanning/documents.mjs +37 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +14 -0
- package/dist/core/scanning/resolvers.mjs +59 -0
- package/dist/core/scanning/schemas.d.mts +13 -0
- package/dist/core/scanning/schemas.mjs +52 -0
- package/dist/core/schema/builder.d.mts +59 -0
- package/dist/core/schema/builder.mjs +78 -0
- package/dist/core/schema/federation.d.mts +33 -0
- package/dist/core/schema/federation.mjs +40 -0
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/server/index.d.mts +4 -0
- package/dist/core/server/index.mjs +4 -0
- package/dist/core/server/sandbox.d.mts +18 -0
- package/dist/core/server/sandbox.mjs +39 -0
- package/dist/core/server/types.d.mts +54 -0
- package/dist/core/server/yoga.d.mts +42 -0
- package/dist/core/server/yoga.mjs +89 -0
- package/dist/core/types/adapter.d.mts +57 -0
- package/dist/core/types/codegen.d.mts +136 -0
- package/dist/core/types/codegen.mjs +1 -0
- package/dist/core/types/config.d.mts +188 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +64 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -34
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +93 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +25 -0
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +18 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +135 -0
- package/dist/core/utils/runtime.d.mts +74 -0
- package/dist/core/utils/runtime.mjs +111 -0
- package/dist/core/utils/subscribe-templates.d.mts +8 -0
- package/dist/core/utils/subscribe-templates.mjs +59 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +33 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/core/watcher/index.d.mts +107 -0
- package/dist/core/watcher/index.mjs +141 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +325 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +29 -0
- package/dist/nitro/adapter.mjs +93 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +59 -0
- package/dist/nitro/codegen.d.mts +18 -0
- package/dist/nitro/codegen.mjs +173 -0
- package/dist/nitro/config.d.mts +50 -0
- package/dist/nitro/config.mjs +57 -0
- package/dist/nitro/index.d.mts +45 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
- package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +53 -0
- package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
- package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
- package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga.mjs +41 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/extend-loader.d.mts +16 -0
- package/dist/nitro/setup/extend-loader.mjs +82 -0
- package/dist/nitro/setup/file-watcher.d.mts +18 -0
- package/dist/nitro/setup/file-watcher.mjs +63 -0
- package/dist/nitro/setup/logging.d.mts +16 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +24 -0
- package/dist/nitro/setup/rollup-integration.mjs +63 -0
- package/dist/nitro/setup/routes.d.mts +13 -0
- package/dist/nitro/setup/routes.mjs +71 -0
- package/dist/nitro/setup/scanner.d.mts +59 -0
- package/dist/nitro/setup/scanner.mjs +120 -0
- package/dist/nitro/setup/ts-config.d.mts +10 -0
- package/dist/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +11 -0
- package/dist/nitro/setup.mjs +191 -0
- package/dist/nitro/types.d.mts +549 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +38 -0
- package/dist/nitro/virtual/generators.mjs +192 -0
- package/dist/nitro/virtual/stubs.d.mts +21 -0
- package/dist/nitro/virtual/stubs.mjs +32 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +112 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/dist/subscribe/index.d.mts +78 -0
- package/dist/subscribe/index.mjs +206 -0
- package/native/index.d.ts +20 -0
- package/native/index.js +585 -0
- package/package.json +201 -111
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -318
- package/dist/rollup.js +0 -277
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/debug.js +0 -449
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -10
- package/dist/types/index.d.ts +0 -246
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/file-generator.d.ts +0 -37
- package/dist/utils/file-generator.js +0 -72
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -278
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -360
- package/dist/virtual/debug-info.d.ts +0 -9
- package/dist/virtual/debug-info.js +0 -26
- package/dist/virtual/graphql-config.d.ts +0 -9
- package/dist/virtual/graphql-config.js +0 -10
- package/dist/virtual/module-config.d.ts +0 -9
- package/dist/virtual/module-config.js +0 -10
- package/dist/virtual/server-directives.d.ts +0 -11
- package/dist/virtual/server-directives.js +0 -10
- package/dist/virtual/server-resolvers.d.ts +0 -11
- package/dist/virtual/server-resolvers.js +0 -10
- package/dist/virtual/server-schemas.d.ts +0 -11
- package/dist/virtual/server-schemas.js +0 -10
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
- /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, ScalarType, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "./types/codegen.mjs";
|
|
2
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineFunction, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, Framework, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLFramework, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_DIR, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_DIR, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, ResolverType, SERVICE_DEFAULT } from "./constants.mjs";
|
|
3
|
+
import { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig } from "./types/config.mjs";
|
|
4
|
+
import { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./types/define.mjs";
|
|
5
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver } from "./types/scanning.mjs";
|
|
6
|
+
import "./types/index.mjs";
|
|
7
|
+
import { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./schema/builder.mjs";
|
|
8
|
+
import { CoreServerInstance, CoreServerOptions, ServerFactory } from "./server/types.mjs";
|
|
9
|
+
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
10
|
+
import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
11
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, SubscriptionInfo, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder } from "./codegen/client.mjs";
|
|
12
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./codegen/plugin.mjs";
|
|
13
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime.mjs";
|
|
14
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./codegen/server.mjs";
|
|
15
|
+
import { validateNoDuplicateTypes, validateSchemaFiles } from "./codegen/validation.mjs";
|
|
16
|
+
import "./codegen/index.mjs";
|
|
17
|
+
import { CreateCoreConfigOptions, createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions } from "./config.mjs";
|
|
18
|
+
import { PackageConfig, ResolvedExtend, ResolvedPackage, isLocalPath, loadPackageConfig, resolvePackageFiles } from "./manifest.mjs";
|
|
19
|
+
import { ASTScanConfig, parseSingleFile, scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
20
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/common.mjs";
|
|
21
|
+
import { parseDirectiveCall, scanDirectivesCore } from "./scanning/directives.mjs";
|
|
22
|
+
import { ScanDocumentsOptions, scanDocumentsCore } from "./scanning/documents.mjs";
|
|
23
|
+
import { parseResolverCall, scanResolversCore } from "./scanning/resolvers.mjs";
|
|
24
|
+
import { scanGraphqlCore, scanSchemasCore } from "./scanning/schemas.mjs";
|
|
25
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
26
|
+
import "./schema/index.mjs";
|
|
27
|
+
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./server/sandbox.mjs";
|
|
28
|
+
import { BASE_SCHEMA as BASE_SCHEMA$1, apolloSandboxHtml, createYogaServer } from "./server/yoga.mjs";
|
|
29
|
+
import "./server/index.mjs";
|
|
30
|
+
import { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./utils/directive-parser.mjs";
|
|
31
|
+
import { MaskErrorOptions, createDefaultMaskError } from "./utils/errors.mjs";
|
|
32
|
+
import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
33
|
+
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
34
|
+
import { createLogger, createSilentLogger, defaultLogger } from "./utils/logger.mjs";
|
|
35
|
+
import { OfetchTemplateOptions, generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
36
|
+
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
37
|
+
export { APOLLO_SANDBOX_CDN, ASTScanConfig, BASE_SCHEMA, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreSdkConfig, CoreSecurityConfig, CoreServerInstance, CoreServerOptions, CoreTypesConfig, CreateCoreConfigOptions, CreateMergedSchemaOptions, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineDirectiveConfig, DefineFunction, DirectiveArgument, DirectiveDefinition, DirectiveFileRef, DirectiveParser, DirectiveWrapper, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, ExternalServiceCodegenConfig, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, Flatten, Framework, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLArgumentType, GraphQLBaseType, GraphQLFramework, GraphQLLoadSchemaOptions, GraphQLScalarType, GraphQLTypeDefPointer, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, MaskErrorOptions, ModuleConfig, OfetchTemplateOptions, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_DIR, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_DIR, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, PackageConfig, ParsedDirective, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, ResolvedExtend, ResolvedPackage, ResolverDefinition, ResolverImport, ResolverType, SERVICE_DEFAULT, ScalarType, ScanContext, ScanDocumentsOptions, ScanResult, ScannedFile, ScannedResolver, SchemaDefinition, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult, ServerFactory, SubscriptionInfo, BASE_SCHEMA$1 as YOGA_BASE_SCHEMA, apolloSandboxHtml, buildGraphQLSchema, createCoreConfig, createCoreContext, createDefaultMaskError, createLogger, createMergedSchema, createSandboxResponse, createScanContext, createSilentLogger, createYogaServer, deduplicateFiles, defaultLogger, directiveParser, downloadAndSaveSchema, ensureDir, extractPaths, extractSubscriptions, fetchSandboxScript, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, generateTypes, getImportId, graphQLLoadSchemaSync, isLocalPath, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, loadPackageConfig, mergeGraphQLOptions, parse, parseDirectiveCall, parseResolverCall, parseSingleFile, pluginContent, readFileSafe, relativeWithDot, resetFederationCache, resolvePackageFiles, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST, subscribe, validate, validateExternalServices, validateNoDuplicateTypes, validateSchemaFiles, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_DIR, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_DIR, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, SERVICE_DEFAULT } from "./constants.mjs";
|
|
2
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./codegen/plugin.mjs";
|
|
3
|
+
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
4
|
+
import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
5
|
+
import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
6
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder } from "./codegen/client.mjs";
|
|
7
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime.mjs";
|
|
8
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./codegen/server.mjs";
|
|
9
|
+
import { validateNoDuplicateTypes, validateSchemaFiles } from "./codegen/validation.mjs";
|
|
10
|
+
import { createLogger, createSilentLogger, defaultLogger } from "./utils/logger.mjs";
|
|
11
|
+
import { createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions } from "./config.mjs";
|
|
12
|
+
import { isLocalPath, loadPackageConfig, resolvePackageFiles } from "./manifest.mjs";
|
|
13
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/common.mjs";
|
|
14
|
+
import { parseSingleFile, scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
15
|
+
import { parseDirectiveCall, scanDirectivesCore } from "./scanning/directives.mjs";
|
|
16
|
+
import { scanDocumentsCore } from "./scanning/documents.mjs";
|
|
17
|
+
import { parseResolverCall, scanResolversCore } from "./scanning/resolvers.mjs";
|
|
18
|
+
import { scanGraphqlCore, scanSchemasCore } from "./scanning/schemas.mjs";
|
|
19
|
+
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
20
|
+
import { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./schema/builder.mjs";
|
|
21
|
+
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./server/sandbox.mjs";
|
|
22
|
+
import { BASE_SCHEMA as BASE_SCHEMA$1, apolloSandboxHtml, createYogaServer } from "./server/yoga.mjs";
|
|
23
|
+
import { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./utils/directive-parser.mjs";
|
|
24
|
+
import { createDefaultMaskError } from "./utils/errors.mjs";
|
|
25
|
+
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
26
|
+
import { generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
27
|
+
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
28
|
+
|
|
29
|
+
export { APOLLO_SANDBOX_CDN, BASE_SCHEMA, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, CODEGEN_EXTERNALS, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_GRAPHQL_CONFIG, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SCHEMA, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_BUILD_NITRO, DIR_BUILD_NUXT, DIR_CLIENT_GRAPHQL, DIR_EXTERNAL, DIR_ROUTES_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DirectiveParser, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FEDERATION_EXTERNALS, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_GRAPHQL_DTS, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_GRAPHQL, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, FRAMEWORK_STANDALONE, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_INTERNAL_ERROR, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, PLACEHOLDER_BUILD_DIR, PLACEHOLDER_CLIENT_DIR, PLACEHOLDER_FRAMEWORK, PLACEHOLDER_ROOT_DIR, PLACEHOLDER_SERVER_DIR, PLACEHOLDER_SERVICE_NAME, PLACEHOLDER_TYPES_DIR, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, RESOLVER_TYPE_DIRECTIVE, RESOLVER_TYPE_MUTATION, RESOLVER_TYPE_QUERY, RESOLVER_TYPE_RESOLVER, RESOLVER_TYPE_SUBSCRIPTION, RESOLVER_TYPE_TYPE, SERVICE_DEFAULT, BASE_SCHEMA$1 as YOGA_BASE_SCHEMA, apolloSandboxHtml, buildGraphQLSchema, createCoreConfig, createCoreContext, createDefaultMaskError, createLogger, createMergedSchema, createSandboxResponse, createScanContext, createSilentLogger, createYogaServer, deduplicateFiles, defaultLogger, directiveParser, downloadAndSaveSchema, ensureDir, extractPaths, extractSubscriptions, fetchSandboxScript, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, generateTypes, getImportId, graphQLLoadSchemaSync, isLocalPath, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, loadPackageConfig, mergeGraphQLOptions, parse, parseDirectiveCall, parseResolverCall, parseSingleFile, pluginContent, readFileSafe, relativeWithDot, resetFederationCache, resolvePackageFiles, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST, subscribe, validate, validateExternalServices, validateNoDuplicateTypes, validateSchemaFiles, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/core/manifest.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Package Config Loader
|
|
4
|
+
* Loads package configuration for extend functionality
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Package config structure (subset of CLIConfig)
|
|
8
|
+
*/
|
|
9
|
+
interface PackageConfig {
|
|
10
|
+
serverDir?: string;
|
|
11
|
+
clientDir?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolved package with config and base directory
|
|
15
|
+
*/
|
|
16
|
+
interface ResolvedPackage {
|
|
17
|
+
config: PackageConfig;
|
|
18
|
+
baseDir: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolved extend paths
|
|
22
|
+
*/
|
|
23
|
+
interface ResolvedExtend {
|
|
24
|
+
schemas: string[];
|
|
25
|
+
resolvers: string[];
|
|
26
|
+
directives: string[];
|
|
27
|
+
documents: string[];
|
|
28
|
+
serverDir: string;
|
|
29
|
+
clientDir?: string;
|
|
30
|
+
/** Path to config.ts if it exists */
|
|
31
|
+
configPath?: string;
|
|
32
|
+
/** Path to schema.ts if it exists */
|
|
33
|
+
schemaPath?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if source is a local path (relative or absolute)
|
|
37
|
+
*/
|
|
38
|
+
declare function isLocalPath(source: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Load config from package or local directory
|
|
41
|
+
* Uses c12 for proper config loading with TypeScript support
|
|
42
|
+
*
|
|
43
|
+
* @param source - Package name or local path (./path, ../path, /absolute/path)
|
|
44
|
+
* @param rootDir - Root directory for resolution
|
|
45
|
+
* @returns Resolved package with config and base directory, or null if not found
|
|
46
|
+
*/
|
|
47
|
+
declare function loadPackageConfig(source: string, rootDir: string): Promise<ResolvedPackage | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Scan package's serverDir and resolve all GraphQL files
|
|
50
|
+
*
|
|
51
|
+
* @param pkg - Resolved package with config
|
|
52
|
+
* @returns Resolved file paths
|
|
53
|
+
*/
|
|
54
|
+
declare function resolvePackageFiles(pkg: ResolvedPackage): Promise<ResolvedExtend>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { PackageConfig, ResolvedExtend, ResolvedPackage, isLocalPath, loadPackageConfig, resolvePackageFiles };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "./constants.mjs";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "pathe";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { loadConfig } from "c12";
|
|
5
|
+
import { resolvePath } from "mlly";
|
|
6
|
+
import { glob } from "tinyglobby";
|
|
7
|
+
|
|
8
|
+
//#region src/core/manifest.ts
|
|
9
|
+
/**
|
|
10
|
+
* Package Config Loader
|
|
11
|
+
* Loads package configuration for extend functionality
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Check if source is a local path (relative or absolute)
|
|
15
|
+
*/
|
|
16
|
+
function isLocalPath(source) {
|
|
17
|
+
return source.startsWith(".") || isAbsolute(source);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Load config from package or local directory
|
|
21
|
+
* Uses c12 for proper config loading with TypeScript support
|
|
22
|
+
*
|
|
23
|
+
* @param source - Package name or local path (./path, ../path, /absolute/path)
|
|
24
|
+
* @param rootDir - Root directory for resolution
|
|
25
|
+
* @returns Resolved package with config and base directory, or null if not found
|
|
26
|
+
*/
|
|
27
|
+
async function loadPackageConfig(source, rootDir) {
|
|
28
|
+
try {
|
|
29
|
+
let pkgDir;
|
|
30
|
+
if (isLocalPath(source)) {
|
|
31
|
+
pkgDir = resolve(rootDir, source);
|
|
32
|
+
if (!existsSync(pkgDir)) return null;
|
|
33
|
+
} else pkgDir = dirname(await resolvePath(`${source}/package.json`, {
|
|
34
|
+
url: rootDir,
|
|
35
|
+
extensions: [".json"]
|
|
36
|
+
}));
|
|
37
|
+
const { config } = await loadConfig({
|
|
38
|
+
name: "nitro-graphql",
|
|
39
|
+
cwd: pkgDir,
|
|
40
|
+
defaultConfig: { serverDir: "server/graphql" }
|
|
41
|
+
});
|
|
42
|
+
const resolvedConfig = {
|
|
43
|
+
serverDir: config?.serverDir || "server/graphql",
|
|
44
|
+
clientDir: config?.clientDir
|
|
45
|
+
};
|
|
46
|
+
if (!existsSync(resolve(pkgDir, resolvedConfig.serverDir))) return null;
|
|
47
|
+
return {
|
|
48
|
+
config: resolvedConfig,
|
|
49
|
+
baseDir: pkgDir
|
|
50
|
+
};
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Scan package's serverDir and resolve all GraphQL files
|
|
57
|
+
*
|
|
58
|
+
* @param pkg - Resolved package with config
|
|
59
|
+
* @returns Resolved file paths
|
|
60
|
+
*/
|
|
61
|
+
async function resolvePackageFiles(pkg) {
|
|
62
|
+
const serverDir = resolve(pkg.baseDir, pkg.config.serverDir || "server/graphql");
|
|
63
|
+
const clientDir = pkg.config.clientDir ? resolve(pkg.baseDir, pkg.config.clientDir) : void 0;
|
|
64
|
+
const schemaPattern = `**/*{${GRAPHQL_EXTENSIONS.join(",")}}`;
|
|
65
|
+
const resolverPattern = `**/*{${RESOLVER_EXTENSIONS.join(",")}}`;
|
|
66
|
+
const directivePattern = `**/*{${DIRECTIVE_EXTENSIONS.join(",")}}`;
|
|
67
|
+
const scanPromises = [
|
|
68
|
+
glob(schemaPattern, {
|
|
69
|
+
cwd: serverDir,
|
|
70
|
+
absolute: true
|
|
71
|
+
}),
|
|
72
|
+
glob(resolverPattern, {
|
|
73
|
+
cwd: serverDir,
|
|
74
|
+
absolute: true
|
|
75
|
+
}),
|
|
76
|
+
glob(directivePattern, {
|
|
77
|
+
cwd: serverDir,
|
|
78
|
+
absolute: true
|
|
79
|
+
})
|
|
80
|
+
];
|
|
81
|
+
if (clientDir && existsSync(clientDir)) scanPromises.push(glob(schemaPattern, {
|
|
82
|
+
cwd: clientDir,
|
|
83
|
+
absolute: true
|
|
84
|
+
}));
|
|
85
|
+
else scanPromises.push(Promise.resolve([]));
|
|
86
|
+
const [schemas = [], resolvers = [], directives = [], documents = []] = await Promise.all(scanPromises);
|
|
87
|
+
const configPath = resolve(serverDir, "config.ts");
|
|
88
|
+
const schemaPath = resolve(serverDir, "schema.ts");
|
|
89
|
+
return {
|
|
90
|
+
schemas: schemas.sort((a, b) => a.localeCompare(b)),
|
|
91
|
+
resolvers: resolvers.sort((a, b) => a.localeCompare(b)),
|
|
92
|
+
directives: directives.sort((a, b) => a.localeCompare(b)),
|
|
93
|
+
documents: documents.sort((a, b) => a.localeCompare(b)),
|
|
94
|
+
serverDir,
|
|
95
|
+
clientDir,
|
|
96
|
+
configPath: existsSync(configPath) ? configPath : void 0,
|
|
97
|
+
schemaPath: existsSync(schemaPath) ? schemaPath : void 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { isLocalPath, loadPackageConfig, resolvePackageFiles };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//#region src/core/pubsub/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Built-in PubSub implementation for GraphQL Subscriptions
|
|
4
|
+
* Simple EventEmitter-based implementation for single-instance deployments
|
|
5
|
+
*
|
|
6
|
+
* For multi-instance deployments, use external PubSub solutions like:
|
|
7
|
+
* - Redis (with ioredis)
|
|
8
|
+
* - Kafka
|
|
9
|
+
* - RabbitMQ
|
|
10
|
+
* - Cloud Pub/Sub services
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Generic PubSub engine interface
|
|
14
|
+
* Compatible with various PubSub implementations
|
|
15
|
+
*/
|
|
16
|
+
interface PubSubEngine<Topics extends Record<string, unknown> = Record<string, unknown>> {
|
|
17
|
+
/**
|
|
18
|
+
* Publish an event to a topic
|
|
19
|
+
* @param topic - Topic name to publish to
|
|
20
|
+
* @param payload - Event payload
|
|
21
|
+
*/
|
|
22
|
+
publish: <K extends keyof Topics>(topic: K, payload: Topics[K]) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Subscribe to a topic
|
|
25
|
+
* @param topic - Topic name to subscribe to
|
|
26
|
+
* @returns AsyncIterable that yields events
|
|
27
|
+
*/
|
|
28
|
+
subscribe: <K extends keyof Topics>(topic: K) => AsyncIterable<Topics[K]>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Type alias for typed PubSub instances
|
|
32
|
+
*/
|
|
33
|
+
type TypedPubSub<Topics extends Record<string, unknown>> = PubSubEngine<Topics>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a simple in-memory PubSub instance
|
|
36
|
+
*
|
|
37
|
+
* This implementation uses EventEmitter for lightweight pub/sub functionality.
|
|
38
|
+
* Suitable for:
|
|
39
|
+
* - Development environments
|
|
40
|
+
* - Single-instance production deployments
|
|
41
|
+
* - Testing
|
|
42
|
+
*
|
|
43
|
+
* NOT suitable for:
|
|
44
|
+
* - Multi-instance/clustered deployments (events won't propagate across instances)
|
|
45
|
+
* - High-throughput scenarios (consider Redis-based PubSub)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Define your topic types
|
|
50
|
+
* interface MyTopics {
|
|
51
|
+
* 'user:created': { id: string; name: string }
|
|
52
|
+
* 'message:sent': { channelId: string; content: string }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // Create typed PubSub instance
|
|
56
|
+
* const pubsub = createPubSub<MyTopics>()
|
|
57
|
+
*
|
|
58
|
+
* // Publish events
|
|
59
|
+
* await pubsub.publish('user:created', { id: '123', name: 'John' })
|
|
60
|
+
*
|
|
61
|
+
* // Subscribe to events (in a resolver)
|
|
62
|
+
* export const userSubscriptions = defineSubscription({
|
|
63
|
+
* userCreated: {
|
|
64
|
+
* subscribe: async function* () {
|
|
65
|
+
* yield* pubsub.subscribe('user:created')
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function createPubSub<Topics extends Record<string, unknown> = Record<string, unknown>>(): PubSubEngine<Topics>;
|
|
72
|
+
/**
|
|
73
|
+
* Filter subscription events based on a predicate
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* export const chatSubscriptions = defineSubscription({
|
|
78
|
+
* messageAdded: {
|
|
79
|
+
* subscribe: async function* (_, { channelId }) {
|
|
80
|
+
* yield* withFilter(
|
|
81
|
+
* pubsub.subscribe('message:added'),
|
|
82
|
+
* (message) => message.channelId === channelId
|
|
83
|
+
* )
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* })
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function withFilter<T>(asyncIterable: AsyncIterable<T>, filter: (value: T) => boolean | Promise<boolean>): AsyncIterable<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Map subscription events to a different shape
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* export const chatSubscriptions = defineSubscription({
|
|
96
|
+
* messageAdded: {
|
|
97
|
+
* subscribe: async function* () {
|
|
98
|
+
* yield* mapAsyncIterator(
|
|
99
|
+
* pubsub.subscribe('message:added'),
|
|
100
|
+
* (event) => ({ messageAdded: event.message })
|
|
101
|
+
* )
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function mapAsyncIterator<T, U>(asyncIterable: AsyncIterable<T>, mapper: (value: T) => U | Promise<U>): AsyncIterable<U>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
|
|
3
|
+
//#region src/core/pubsub/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Built-in PubSub implementation for GraphQL Subscriptions
|
|
6
|
+
* Simple EventEmitter-based implementation for single-instance deployments
|
|
7
|
+
*
|
|
8
|
+
* For multi-instance deployments, use external PubSub solutions like:
|
|
9
|
+
* - Redis (with ioredis)
|
|
10
|
+
* - Kafka
|
|
11
|
+
* - RabbitMQ
|
|
12
|
+
* - Cloud Pub/Sub services
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Create a simple in-memory PubSub instance
|
|
16
|
+
*
|
|
17
|
+
* This implementation uses EventEmitter for lightweight pub/sub functionality.
|
|
18
|
+
* Suitable for:
|
|
19
|
+
* - Development environments
|
|
20
|
+
* - Single-instance production deployments
|
|
21
|
+
* - Testing
|
|
22
|
+
*
|
|
23
|
+
* NOT suitable for:
|
|
24
|
+
* - Multi-instance/clustered deployments (events won't propagate across instances)
|
|
25
|
+
* - High-throughput scenarios (consider Redis-based PubSub)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Define your topic types
|
|
30
|
+
* interface MyTopics {
|
|
31
|
+
* 'user:created': { id: string; name: string }
|
|
32
|
+
* 'message:sent': { channelId: string; content: string }
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // Create typed PubSub instance
|
|
36
|
+
* const pubsub = createPubSub<MyTopics>()
|
|
37
|
+
*
|
|
38
|
+
* // Publish events
|
|
39
|
+
* await pubsub.publish('user:created', { id: '123', name: 'John' })
|
|
40
|
+
*
|
|
41
|
+
* // Subscribe to events (in a resolver)
|
|
42
|
+
* export const userSubscriptions = defineSubscription({
|
|
43
|
+
* userCreated: {
|
|
44
|
+
* subscribe: async function* () {
|
|
45
|
+
* yield* pubsub.subscribe('user:created')
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function createPubSub() {
|
|
52
|
+
const emitter = new EventEmitter();
|
|
53
|
+
emitter.setMaxListeners(0);
|
|
54
|
+
return {
|
|
55
|
+
async publish(topic, payload) {
|
|
56
|
+
emitter.emit(String(topic), payload);
|
|
57
|
+
},
|
|
58
|
+
subscribe(topic) {
|
|
59
|
+
const topicStr = String(topic);
|
|
60
|
+
return { [Symbol.asyncIterator]() {
|
|
61
|
+
const queue = [];
|
|
62
|
+
let resolve = null;
|
|
63
|
+
let done = false;
|
|
64
|
+
const listener = (payload) => {
|
|
65
|
+
if (resolve) {
|
|
66
|
+
resolve({
|
|
67
|
+
value: payload,
|
|
68
|
+
done: false
|
|
69
|
+
});
|
|
70
|
+
resolve = null;
|
|
71
|
+
} else queue.push(payload);
|
|
72
|
+
};
|
|
73
|
+
emitter.on(topicStr, listener);
|
|
74
|
+
return {
|
|
75
|
+
next() {
|
|
76
|
+
if (done) return Promise.resolve({
|
|
77
|
+
value: void 0,
|
|
78
|
+
done: true
|
|
79
|
+
});
|
|
80
|
+
if (queue.length > 0) return Promise.resolve({
|
|
81
|
+
value: queue.shift(),
|
|
82
|
+
done: false
|
|
83
|
+
});
|
|
84
|
+
return new Promise((r) => {
|
|
85
|
+
resolve = r;
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
return() {
|
|
89
|
+
done = true;
|
|
90
|
+
emitter.off(topicStr, listener);
|
|
91
|
+
return Promise.resolve({
|
|
92
|
+
value: void 0,
|
|
93
|
+
done: true
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
throw(error) {
|
|
97
|
+
done = true;
|
|
98
|
+
emitter.off(topicStr, listener);
|
|
99
|
+
return Promise.reject(error);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
} };
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Filter subscription events based on a predicate
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* export const chatSubscriptions = defineSubscription({
|
|
112
|
+
* messageAdded: {
|
|
113
|
+
* subscribe: async function* (_, { channelId }) {
|
|
114
|
+
* yield* withFilter(
|
|
115
|
+
* pubsub.subscribe('message:added'),
|
|
116
|
+
* (message) => message.channelId === channelId
|
|
117
|
+
* )
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* })
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
async function* withFilter(asyncIterable, filter) {
|
|
124
|
+
for await (const value of asyncIterable) if (await filter(value)) yield value;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Map subscription events to a different shape
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* export const chatSubscriptions = defineSubscription({
|
|
132
|
+
* messageAdded: {
|
|
133
|
+
* subscribe: async function* () {
|
|
134
|
+
* yield* mapAsyncIterator(
|
|
135
|
+
* pubsub.subscribe('message:added'),
|
|
136
|
+
* (event) => ({ messageAdded: event.message })
|
|
137
|
+
* )
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
* })
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
async function* mapAsyncIterator(asyncIterable, mapper) {
|
|
144
|
+
for await (const value of asyncIterable) yield await mapper(value);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
export { createPubSub, mapAsyncIterator, withFilter };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ResolverImport, ScanContext, ScanResult, ScannedResolver } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/ast-scanner.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for AST-based scanning
|
|
6
|
+
*/
|
|
7
|
+
interface ASTScanConfig {
|
|
8
|
+
/** Glob pattern for files to scan */
|
|
9
|
+
pattern: string;
|
|
10
|
+
/** Parse a function call and return import info, or null if not a valid export */
|
|
11
|
+
parseCall: (calleeName: string, exportName: string, filePath: string) => ResolverImport | null;
|
|
12
|
+
/** Whether to emit warnings for common issues (default: true for resolvers) */
|
|
13
|
+
emitWarnings?: boolean;
|
|
14
|
+
/** Valid function names for warning messages */
|
|
15
|
+
validFunctions?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Scan files matching a pattern and parse their exports using AST
|
|
19
|
+
*/
|
|
20
|
+
declare function scanWithAST(ctx: ScanContext, config: ASTScanConfig): Promise<ScanResult<ScannedResolver>>;
|
|
21
|
+
/**
|
|
22
|
+
* Parse a single file and extract exports using AST
|
|
23
|
+
* Used for manifest resolver files
|
|
24
|
+
*/
|
|
25
|
+
declare function parseSingleFile(filePath: string, parseCall: (calleeName: string, exportName: string, filePath: string) => ResolverImport | null): Promise<ScannedResolver | null>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ASTScanConfig, parseSingleFile, scanWithAST };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { scanDirectory } from "./common.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { basename, relative } from "pathe";
|
|
4
|
+
import { parseSync } from "oxc-parser";
|
|
5
|
+
|
|
6
|
+
//#region src/core/scanning/ast-scanner.ts
|
|
7
|
+
/**
|
|
8
|
+
* Scan files matching a pattern and parse their exports using AST
|
|
9
|
+
*/
|
|
10
|
+
async function scanWithAST(ctx, config) {
|
|
11
|
+
const warnings = [];
|
|
12
|
+
const errors = [];
|
|
13
|
+
try {
|
|
14
|
+
const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
|
|
15
|
+
const files = await scanDirectory(ctx, ctx.rootDir, serverDirRelative, config.pattern);
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const file of files) try {
|
|
18
|
+
const fileContent = await readFile(file.fullPath, "utf-8");
|
|
19
|
+
const parsed = parseSync(file.fullPath, fileContent);
|
|
20
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
21
|
+
if (ctx.isDev) {
|
|
22
|
+
const fileName = basename(file.fullPath);
|
|
23
|
+
const firstError = parsed.errors[0];
|
|
24
|
+
const location = firstError?.labels?.[0];
|
|
25
|
+
const lineInfo = location ? `:${location.start}` : "";
|
|
26
|
+
const message = firstError?.message.split(",")[0] || "Syntax error";
|
|
27
|
+
errors.push(`${fileName}${lineInfo} - ${message}`);
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const result = parseExports(file.fullPath, parsed.program, config);
|
|
32
|
+
if (ctx.isDev && config.emitWarnings && result.warnings.length > 0) {
|
|
33
|
+
const relPath = relative(ctx.rootDir, file.fullPath);
|
|
34
|
+
for (const warning of result.warnings) warnings.push(`${relPath}: ${warning}`);
|
|
35
|
+
}
|
|
36
|
+
if (result.resolver.imports.length > 0) results.push(result.resolver);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const relPath = relative(ctx.rootDir, file.fullPath);
|
|
39
|
+
errors.push(`Failed to parse file ${relPath}: ${error}`);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
items: results,
|
|
43
|
+
warnings,
|
|
44
|
+
errors
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
errors.push(`Scanning error: ${error}`);
|
|
48
|
+
return {
|
|
49
|
+
items: [],
|
|
50
|
+
warnings,
|
|
51
|
+
errors
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse a single file and extract exports using AST
|
|
57
|
+
* Used for manifest resolver files
|
|
58
|
+
*/
|
|
59
|
+
async function parseSingleFile(filePath, parseCall) {
|
|
60
|
+
try {
|
|
61
|
+
const parsed = parseSync(filePath, await readFile(filePath, "utf-8"));
|
|
62
|
+
if (parsed.errors && parsed.errors.length > 0) return null;
|
|
63
|
+
const result = parseExports(filePath, parsed.program, {
|
|
64
|
+
pattern: "",
|
|
65
|
+
parseCall,
|
|
66
|
+
emitWarnings: false
|
|
67
|
+
});
|
|
68
|
+
if (result.resolver.imports.length > 0) return result.resolver;
|
|
69
|
+
return null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse exports from AST program
|
|
76
|
+
*/
|
|
77
|
+
function parseExports(filePath, program, config) {
|
|
78
|
+
const warnings = [];
|
|
79
|
+
const resolver = {
|
|
80
|
+
specifier: filePath,
|
|
81
|
+
imports: []
|
|
82
|
+
};
|
|
83
|
+
let hasDefaultExport = false;
|
|
84
|
+
let hasNamedExport = false;
|
|
85
|
+
const namedExports = [];
|
|
86
|
+
for (const node of program.body) {
|
|
87
|
+
if (node.type === "ExportDefaultDeclaration") hasDefaultExport = true;
|
|
88
|
+
if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "VariableDeclaration") {
|
|
89
|
+
for (const decl of node.declaration.declarations) if (decl.type === "VariableDeclarator" && decl.init && decl.id.type === "Identifier") {
|
|
90
|
+
hasNamedExport = true;
|
|
91
|
+
namedExports.push(decl.id.name);
|
|
92
|
+
if (decl.init && decl.init.type === "CallExpression") {
|
|
93
|
+
if (decl.init.callee.type === "Identifier") {
|
|
94
|
+
const imp = config.parseCall(decl.init.callee.name, decl.id.name, filePath);
|
|
95
|
+
if (imp) resolver.imports.push(imp);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (config.emitWarnings) {
|
|
102
|
+
if (hasDefaultExport && !hasNamedExport) warnings.push("Using default export instead of named export. Must use named exports like \"export const myResolver = defineQuery(...)\". Default exports are not detected.");
|
|
103
|
+
if (resolver.imports.length === 0 && hasNamedExport) {
|
|
104
|
+
const validFunctions = config.validFunctions?.join(", ") || "define* functions";
|
|
105
|
+
warnings.push(`File has named exports [${namedExports.join(", ")}] but none use the required define functions (${validFunctions}). Exports will not be registered.`);
|
|
106
|
+
}
|
|
107
|
+
if (!hasDefaultExport && !hasNamedExport) warnings.push("No exports found. Files must export using define* functions.");
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
resolver,
|
|
111
|
+
warnings
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { parseSingleFile, scanWithAST };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ScanContext, ScannedFile } from "../types/scanning.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/scanning/common.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Scan a directory for files matching a glob pattern
|
|
6
|
+
*/
|
|
7
|
+
declare function scanDirectory(ctx: ScanContext, baseDir: string, subDir: string, globPattern?: string): Promise<ScannedFile[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Deduplicate files by fullPath
|
|
10
|
+
*/
|
|
11
|
+
declare function deduplicateFiles<T extends {
|
|
12
|
+
fullPath: string;
|
|
13
|
+
}>(files: T[]): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Filter files by extension
|
|
16
|
+
*/
|
|
17
|
+
declare function filterByExtension<T extends {
|
|
18
|
+
fullPath: string;
|
|
19
|
+
}>(files: T[], extensions: readonly string[]): T[];
|
|
20
|
+
/**
|
|
21
|
+
* Extract file paths from scanned files
|
|
22
|
+
*/
|
|
23
|
+
declare function extractPaths(files: ScannedFile[]): string[];
|
|
24
|
+
//#endregion
|
|
25
|
+
export { deduplicateFiles, extractPaths, filterByExtension, scanDirectory };
|