@graphoria/server 0.1.0
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/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +129 -0
- package/cli.ts +105 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/src/ai/agent/agent.d.ts +37 -0
- package/dist/src/ai/agent/agent.d.ts.map +1 -0
- package/dist/src/ai/agent/index.d.ts +3 -0
- package/dist/src/ai/agent/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts +10 -0
- package/dist/src/ai/agent/providers/anthropic.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/index.d.ts +8 -0
- package/dist/src/ai/agent/providers/index.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/ollama.d.ts +11 -0
- package/dist/src/ai/agent/providers/ollama.d.ts.map +1 -0
- package/dist/src/ai/agent/providers/openai.d.ts +14 -0
- package/dist/src/ai/agent/providers/openai.d.ts.map +1 -0
- package/dist/src/ai/agent/types.d.ts +51 -0
- package/dist/src/ai/agent/types.d.ts.map +1 -0
- package/dist/src/ai/ask-field.test.d.ts +2 -0
- package/dist/src/ai/ask-field.test.d.ts.map +1 -0
- package/dist/src/ai/index.d.ts +7 -0
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.d.ts +14 -0
- package/dist/src/ai/mcp/create-server.d.ts.map +1 -0
- package/dist/src/ai/mcp/create-server.test.d.ts +2 -0
- package/dist/src/ai/mcp/create-server.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.d.ts +13 -0
- package/dist/src/ai/mcp/index.d.ts.map +1 -0
- package/dist/src/ai/mcp/index.test.d.ts +2 -0
- package/dist/src/ai/mcp/index.test.d.ts.map +1 -0
- package/dist/src/ai/mcp/instructions.d.ts +2 -0
- package/dist/src/ai/mcp/instructions.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.d.ts +4 -0
- package/dist/src/ai/tools/agent.d.ts.map +1 -0
- package/dist/src/ai/tools/agent.test.d.ts +2 -0
- package/dist/src/ai/tools/agent.test.d.ts.map +1 -0
- package/dist/src/ai/tools/core.d.ts +75 -0
- package/dist/src/ai/tools/core.d.ts.map +1 -0
- package/dist/src/ai/tools/query-data.d.ts +35 -0
- package/dist/src/ai/tools/query-data.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts +5 -0
- package/dist/src/analyzeQuery/analyzers/fragmentAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/operationAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts +6 -0
- package/dist/src/analyzeQuery/analyzers/selectionAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts +4 -0
- package/dist/src/analyzeQuery/analyzers/variableAnalyzer.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts +16 -0
- package/dist/src/analyzeQuery/depthLimit.d.ts.map +1 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts +2 -0
- package/dist/src/analyzeQuery/depthLimit.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts +4 -0
- package/dist/src/analyzeQuery/directiveUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts +2 -0
- package/dist/src/analyzeQuery/directiveUtils.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.d.ts +5 -0
- package/dist/src/analyzeQuery/index.d.ts.map +1 -0
- package/dist/src/analyzeQuery/index.test.d.ts +2 -0
- package/dist/src/analyzeQuery/index.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts +71 -0
- package/dist/src/analyzeQuery/resolveVariables.d.ts.map +1 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts +2 -0
- package/dist/src/analyzeQuery/resolveVariables.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts +2 -0
- package/dist/src/analyzeQuery/staticValues.test.d.ts.map +1 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts +9 -0
- package/dist/src/analyzeQuery/typeUtils.d.ts.map +1 -0
- package/dist/src/analyzeQuery/types.d.ts +54 -0
- package/dist/src/analyzeQuery/types.d.ts.map +1 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts +4 -0
- package/dist/src/analyzeQuery/valueExtractors.d.ts.map +1 -0
- package/dist/src/authentication/duration.d.ts +14 -0
- package/dist/src/authentication/duration.d.ts.map +1 -0
- package/dist/src/authentication/duration.test.d.ts +2 -0
- package/dist/src/authentication/duration.test.d.ts.map +1 -0
- package/dist/src/authentication/index.d.ts +4 -0
- package/dist/src/authentication/index.d.ts.map +1 -0
- package/dist/src/authentication/index.test.d.ts +2 -0
- package/dist/src/authentication/index.test.d.ts.map +1 -0
- package/dist/src/authentication/jwt.d.ts +10 -0
- package/dist/src/authentication/jwt.d.ts.map +1 -0
- package/dist/src/authentication/jwt.test.d.ts +2 -0
- package/dist/src/authentication/jwt.test.d.ts.map +1 -0
- package/dist/src/authentication/paseto.d.ts +7 -0
- package/dist/src/authentication/paseto.d.ts.map +1 -0
- package/dist/src/authentication/paseto.test.d.ts +2 -0
- package/dist/src/authentication/paseto.test.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.d.ts +14 -0
- package/dist/src/authentication/tokenRepository.d.ts.map +1 -0
- package/dist/src/authentication/tokenRepository.test.d.ts +2 -0
- package/dist/src/authentication/tokenRepository.test.d.ts.map +1 -0
- package/dist/src/authentication/types.d.ts +42 -0
- package/dist/src/authentication/types.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.d.ts +4 -0
- package/dist/src/cli/seedAuth.d.ts.map +1 -0
- package/dist/src/cli/seedAuth.test.d.ts +2 -0
- package/dist/src/cli/seedAuth.test.d.ts.map +1 -0
- package/dist/src/cli/seedAuthArgs.d.ts +9 -0
- package/dist/src/cli/seedAuthArgs.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.d.ts +21 -0
- package/dist/src/config/helpers/cronHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/cronHelper.test.d.ts.map +1 -0
- package/dist/src/config/helpers/index.d.ts +4 -0
- package/dist/src/config/helpers/index.d.ts.map +1 -0
- package/dist/src/config/helpers/operationHelper.d.ts +44 -0
- package/dist/src/config/helpers/operationHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.d.ts +20 -0
- package/dist/src/config/helpers/queueHelper.d.ts.map +1 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts +2 -0
- package/dist/src/config/helpers/queueHelper.test.d.ts.map +1 -0
- package/dist/src/config/index.d.ts +236 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/types/ai.d.ts +29 -0
- package/dist/src/config/types/ai.d.ts.map +1 -0
- package/dist/src/config/types/auth.d.ts +112 -0
- package/dist/src/config/types/auth.d.ts.map +1 -0
- package/dist/src/config/types/configuration.d.ts +61 -0
- package/dist/src/config/types/configuration.d.ts.map +1 -0
- package/dist/src/config/types/cron.d.ts +81 -0
- package/dist/src/config/types/cron.d.ts.map +1 -0
- package/dist/src/config/types/db.d.ts +210 -0
- package/dist/src/config/types/db.d.ts.map +1 -0
- package/dist/src/config/types/index.d.ts +17 -0
- package/dist/src/config/types/index.d.ts.map +1 -0
- package/dist/src/config/types/operation.d.ts +226 -0
- package/dist/src/config/types/operation.d.ts.map +1 -0
- package/dist/src/config/types/queue.d.ts +142 -0
- package/dist/src/config/types/queue.d.ts.map +1 -0
- package/dist/src/config/types/remote-rest.d.ts +18 -0
- package/dist/src/config/types/remote-rest.d.ts.map +1 -0
- package/dist/src/config/types/remote-schema.d.ts +27 -0
- package/dist/src/config/types/remote-schema.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.d.ts +89 -0
- package/dist/src/config/types/virtual-columns.d.ts.map +1 -0
- package/dist/src/config/types/virtual-columns.test.d.ts +2 -0
- package/dist/src/config/types/virtual-columns.test.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/index.d.ts +867 -0
- package/dist/src/configuration/getSchemas/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts +412 -0
- package/dist/src/configuration/getSchemas/mergeEntities/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts +16 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.d.ts.map +1 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts +2 -0
- package/dist/src/configuration/getSchemas/type-definition-generator/index.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.d.ts +31 -0
- package/dist/src/configuration/gql/buildExecute.d.ts.map +1 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts +2 -0
- package/dist/src/configuration/gql/buildExecute.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts +9 -0
- package/dist/src/configuration/gql/gqlAuthOperations.d.ts.map +1 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts +2 -0
- package/dist/src/configuration/gql/gqlAuthOperations.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts +28 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/gql/handleGraphQLRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts +19 -0
- package/dist/src/configuration/gql/handleGraphQLSubscriptionFactory.d.ts.map +1 -0
- package/dist/src/configuration/index.d.ts +719 -0
- package/dist/src/configuration/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts +19 -0
- package/dist/src/configuration/rest/generateOpenAPI.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts +12 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.d.ts.map +1 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts +2 -0
- package/dist/src/configuration/rest/handleRESTRequestFactory.test.d.ts.map +1 -0
- package/dist/src/configuration/rest/index.d.ts +20 -0
- package/dist/src/configuration/rest/index.d.ts.map +1 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts +71 -0
- package/dist/src/configuration/rest/openApiErrors.d.ts.map +1 -0
- package/dist/src/console/App.d.ts +3 -0
- package/dist/src/console/App.d.ts.map +1 -0
- package/dist/src/console/Login.d.ts +6 -0
- package/dist/src/console/Login.d.ts.map +1 -0
- package/dist/src/console/api.d.ts +17 -0
- package/dist/src/console/api.d.ts.map +1 -0
- package/dist/src/console/api.test.d.ts +2 -0
- package/dist/src/console/api.test.d.ts.map +1 -0
- package/dist/src/console/client.d.ts +67 -0
- package/dist/src/console/client.d.ts.map +1 -0
- package/dist/src/console/frontend.d.ts +8 -0
- package/dist/src/console/frontend.d.ts.map +1 -0
- package/dist/src/console/pages/ConfigPage.d.ts +2 -0
- package/dist/src/console/pages/ConfigPage.d.ts.map +1 -0
- package/dist/src/console/pages/RolesPage.d.ts +2 -0
- package/dist/src/console/pages/RolesPage.d.ts.map +1 -0
- package/dist/src/console/pages/StatusPage.d.ts +2 -0
- package/dist/src/console/pages/StatusPage.d.ts.map +1 -0
- package/dist/src/console/pages/TablesPage.d.ts +2 -0
- package/dist/src/console/pages/TablesPage.d.ts.map +1 -0
- package/dist/src/console/useApi.d.ts +8 -0
- package/dist/src/console/useApi.d.ts.map +1 -0
- package/dist/src/cron/index.d.ts +63 -0
- package/dist/src/cron/index.d.ts.map +1 -0
- package/dist/src/databases/auth/auth-operations.d.ts +11 -0
- package/dist/src/databases/auth/auth-operations.d.ts.map +1 -0
- package/dist/src/databases/auth/password.d.ts +3 -0
- package/dist/src/databases/auth/password.d.ts.map +1 -0
- package/dist/src/databases/auth/password.test.d.ts +2 -0
- package/dist/src/databases/auth/password.test.d.ts.map +1 -0
- package/dist/src/databases/common.d.ts +53 -0
- package/dist/src/databases/common.d.ts.map +1 -0
- package/dist/src/databases/common.test.d.ts +2 -0
- package/dist/src/databases/common.test.d.ts.map +1 -0
- package/dist/src/databases/core/executor.d.ts +10 -0
- package/dist/src/databases/core/executor.d.ts.map +1 -0
- package/dist/src/databases/core/executor.test.d.ts +2 -0
- package/dist/src/databases/core/executor.test.d.ts.map +1 -0
- package/dist/src/databases/core/function-mapping.d.ts +38 -0
- package/dist/src/databases/core/function-mapping.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.d.ts +2 -0
- package/dist/src/databases/core/identifier.d.ts.map +1 -0
- package/dist/src/databases/core/identifier.test.d.ts +2 -0
- package/dist/src/databases/core/identifier.test.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.d.ts +64 -0
- package/dist/src/databases/core/query-builder.d.ts.map +1 -0
- package/dist/src/databases/core/query-builder.test.d.ts +2 -0
- package/dist/src/databases/core/query-builder.test.d.ts.map +1 -0
- package/dist/src/databases/directives.d.ts +16 -0
- package/dist/src/databases/directives.d.ts.map +1 -0
- package/dist/src/databases/directives.test.d.ts +2 -0
- package/dist/src/databases/directives.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mssql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mssql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/format.d.ts +5 -0
- package/dist/src/databases/engines/mssql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mssql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mssql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mssql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mssql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.d.ts +9 -0
- package/dist/src/databases/engines/mysql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/connection.d.ts +14 -0
- package/dist/src/databases/engines/mysql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/format.d.ts +5 -0
- package/dist/src/databases/engines/mysql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/mysql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/mysql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/mysql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/mysql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts +9 -0
- package/dist/src/databases/engines/postgresql/auth.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/auth.test.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts +14 -0
- package/dist/src/databases/engines/postgresql/connection.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/format.d.ts +5 -0
- package/dist/src/databases/engines/postgresql/format.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts +48 -0
- package/dist/src/databases/engines/postgresql/getStructure.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/getViews.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts +7 -0
- package/dist/src/databases/engines/postgresql/query/index.d.ts.map +1 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts +2 -0
- package/dist/src/databases/engines/postgresql/query/index.test.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/claims.d.ts +2 -0
- package/dist/src/databases/engines/shared/claims.d.ts.map +1 -0
- package/dist/src/databases/engines/shared/types.d.ts +8 -0
- package/dist/src/databases/engines/shared/types.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.d.ts +146 -0
- package/dist/src/databases/high-level-operations.d.ts.map +1 -0
- package/dist/src/databases/high-level-operations.test.d.ts +2 -0
- package/dist/src/databases/high-level-operations.test.d.ts.map +1 -0
- package/dist/src/databases/index.d.ts +8 -0
- package/dist/src/databases/index.d.ts.map +1 -0
- package/dist/src/databases/metadata/structure.d.ts +56 -0
- package/dist/src/databases/metadata/structure.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/convert.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts +15 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateCreateTable/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts +18 -0
- package/dist/src/databases/schemaBuilder/generateCreateView/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateInsert/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts +7 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/generateSchemaCreation/index.test.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts +2 -0
- package/dist/src/databases/schemaBuilder/mssqlToPostgres/convertView.d.ts.map +1 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts +8 -0
- package/dist/src/databases/schemaBuilder/utils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.d.ts +24 -0
- package/dist/src/databases/sqlTypeUtils.d.ts.map +1 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts +2 -0
- package/dist/src/databases/sqlTypeUtils.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.d.ts +215 -0
- package/dist/src/databases/transformers/data-transformers.d.ts.map +1 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts +2 -0
- package/dist/src/databases/transformers/data-transformers.test.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.d.ts.map +1 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts +2 -0
- package/dist/src/databases/transformers/genResolverName.test.d.ts.map +1 -0
- package/dist/src/index.d.ts +139 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/logging/index.d.ts +21 -0
- package/dist/src/logging/index.d.ts.map +1 -0
- package/dist/src/queues/kafka.d.ts +22 -0
- package/dist/src/queues/kafka.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.d.ts +34 -0
- package/dist/src/queues/rabbitmq.d.ts.map +1 -0
- package/dist/src/queues/rabbitmq.test.d.ts +2 -0
- package/dist/src/queues/rabbitmq.test.d.ts.map +1 -0
- package/dist/src/remoteREST/index.d.ts +13 -0
- package/dist/src/remoteREST/index.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.d.ts +8 -0
- package/dist/src/remoteREST/parse.d.ts.map +1 -0
- package/dist/src/remoteREST/parse.test.d.ts +2 -0
- package/dist/src/remoteREST/parse.test.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.d.ts +6 -0
- package/dist/src/remoteREST/proxy.d.ts.map +1 -0
- package/dist/src/remoteREST/proxy.test.d.ts +2 -0
- package/dist/src/remoteREST/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.d.ts +8 -0
- package/dist/src/remoteREST/transform.d.ts.map +1 -0
- package/dist/src/remoteREST/transform.test.d.ts +2 -0
- package/dist/src/remoteREST/transform.test.d.ts.map +1 -0
- package/dist/src/remoteREST/types.d.ts +37 -0
- package/dist/src/remoteREST/types.d.ts.map +1 -0
- package/dist/src/remoteSchemas/index.d.ts +13 -0
- package/dist/src/remoteSchemas/index.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.d.ts +7 -0
- package/dist/src/remoteSchemas/introspect.d.ts.map +1 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts +2 -0
- package/dist/src/remoteSchemas/introspect.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.d.ts +7 -0
- package/dist/src/remoteSchemas/proxy.d.ts.map +1 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts +2 -0
- package/dist/src/remoteSchemas/proxy.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.d.ts +9 -0
- package/dist/src/remoteSchemas/transform.d.ts.map +1 -0
- package/dist/src/remoteSchemas/transform.test.d.ts +2 -0
- package/dist/src/remoteSchemas/transform.test.d.ts.map +1 -0
- package/dist/src/remoteSchemas/types.d.ts +41 -0
- package/dist/src/remoteSchemas/types.d.ts.map +1 -0
- package/dist/src/singletons/ai.d.ts +25 -0
- package/dist/src/singletons/ai.d.ts.map +1 -0
- package/dist/src/singletons/ai.test.d.ts +2 -0
- package/dist/src/singletons/ai.test.d.ts.map +1 -0
- package/dist/src/singletons/authentication.d.ts +4 -0
- package/dist/src/singletons/authentication.d.ts.map +1 -0
- package/dist/src/singletons/cache/index.d.ts +5 -0
- package/dist/src/singletons/cache/index.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts +12 -0
- package/dist/src/singletons/cache/lruCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts +2 -0
- package/dist/src/singletons/cache/lruCacheStore.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts +16 -0
- package/dist/src/singletons/cache/redisCacheStore.d.ts.map +1 -0
- package/dist/src/singletons/cache/redisClient.d.ts +3 -0
- package/dist/src/singletons/cache/redisClient.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.d.ts +7 -0
- package/dist/src/singletons/cache/registry.d.ts.map +1 -0
- package/dist/src/singletons/cache/registry.test.d.ts +2 -0
- package/dist/src/singletons/cache/registry.test.d.ts.map +1 -0
- package/dist/src/singletons/cache/types.d.ts +8 -0
- package/dist/src/singletons/cache/types.d.ts.map +1 -0
- package/dist/src/singletons/cron.d.ts +69 -0
- package/dist/src/singletons/cron.d.ts.map +1 -0
- package/dist/src/singletons/databases.d.ts +27 -0
- package/dist/src/singletons/databases.d.ts.map +1 -0
- package/dist/src/singletons/databases.test.d.ts +2 -0
- package/dist/src/singletons/databases.test.d.ts.map +1 -0
- package/dist/src/singletons/env.d.ts +494 -0
- package/dist/src/singletons/env.d.ts.map +1 -0
- package/dist/src/singletons/queues.d.ts +17 -0
- package/dist/src/singletons/queues.d.ts.map +1 -0
- package/dist/src/subscriptions/index.d.ts +4 -0
- package/dist/src/subscriptions/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/database.d.ts +12 -0
- package/dist/src/subscriptions/strategies/database.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/index.d.ts +12 -0
- package/dist/src/subscriptions/strategies/index.d.ts.map +1 -0
- package/dist/src/subscriptions/strategies/queue.d.ts +11 -0
- package/dist/src/subscriptions/strategies/queue.d.ts.map +1 -0
- package/dist/src/subscriptions/types.d.ts +67 -0
- package/dist/src/subscriptions/types.d.ts.map +1 -0
- package/dist/src/subscriptions/utils/polling.d.ts +17 -0
- package/dist/src/subscriptions/utils/polling.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +44 -0
- package/dist/src/types/common.d.ts.map +1 -0
- package/dist/src/types/configuration.d.ts +28 -0
- package/dist/src/types/configuration.d.ts.map +1 -0
- package/dist/src/types/db.d.ts +43 -0
- package/dist/src/types/db.d.ts.map +1 -0
- package/dist/src/types/env.d.ts +2302 -0
- package/dist/src/types/env.d.ts.map +1 -0
- package/dist/src/types/env.test.d.ts +2 -0
- package/dist/src/types/env.test.d.ts.map +1 -0
- package/dist/src/types/resolver.d.ts +121 -0
- package/dist/src/types/resolver.d.ts.map +1 -0
- package/dist/src/types/zod/ai.d.ts +6 -0
- package/dist/src/types/zod/ai.d.ts.map +1 -0
- package/dist/src/types/zod/auth.d.ts +76 -0
- package/dist/src/types/zod/auth.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.d.ts +1278 -0
- package/dist/src/types/zod/configuration.d.ts.map +1 -0
- package/dist/src/types/zod/configuration.test.d.ts +2 -0
- package/dist/src/types/zod/configuration.test.d.ts.map +1 -0
- package/dist/src/types/zod/cron.d.ts +32 -0
- package/dist/src/types/zod/cron.d.ts.map +1 -0
- package/dist/src/types/zod/db.d.ts +441 -0
- package/dist/src/types/zod/db.d.ts.map +1 -0
- package/dist/src/types/zod/db.test.d.ts +2 -0
- package/dist/src/types/zod/db.test.d.ts.map +1 -0
- package/dist/src/types/zod/mcp.d.ts +6 -0
- package/dist/src/types/zod/mcp.d.ts.map +1 -0
- package/dist/src/types/zod/operation.d.ts +9 -0
- package/dist/src/types/zod/operation.d.ts.map +1 -0
- package/dist/src/types/zod/queue.d.ts +656 -0
- package/dist/src/types/zod/queue.d.ts.map +1 -0
- package/dist/src/types/zod/queue.test.d.ts +2 -0
- package/dist/src/types/zod/queue.test.d.ts.map +1 -0
- package/dist/src/types/zod/remoteREST.d.ts +6 -0
- package/dist/src/types/zod/remoteREST.d.ts.map +1 -0
- package/dist/src/types/zod/remoteSchema.d.ts +6 -0
- package/dist/src/types/zod/remoteSchema.d.ts.map +1 -0
- package/dist/src/utils/benchmark.d.ts +2 -0
- package/dist/src/utils/benchmark.d.ts.map +1 -0
- package/dist/src/utils/event-emitter.d.ts +19 -0
- package/dist/src/utils/event-emitter.d.ts.map +1 -0
- package/dist/src/utils/responses.d.ts +19 -0
- package/dist/src/utils/responses.d.ts.map +1 -0
- package/dist/src/utils/responses.test.d.ts +2 -0
- package/dist/src/utils/responses.test.d.ts.map +1 -0
- package/dist/src/utils/safeJSONParse.d.ts +2 -0
- package/dist/src/utils/safeJSONParse.d.ts.map +1 -0
- package/dist/src/utils/selection.d.ts +3 -0
- package/dist/src/utils/selection.d.ts.map +1 -0
- package/dist/src/utils/selection.test.d.ts +2 -0
- package/dist/src/utils/selection.test.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.d.ts +47 -0
- package/dist/src/utils/sessionVariables.d.ts.map +1 -0
- package/dist/src/utils/sessionVariables.test.d.ts +2 -0
- package/dist/src/utils/sessionVariables.test.d.ts.map +1 -0
- package/dist/src/utils/writeSchema.d.ts +3 -0
- package/dist/src/utils/writeSchema.d.ts.map +1 -0
- package/dist/standalone.d.ts +3 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +119 -0
- package/playgrounds/console/index.html +25 -0
- package/playgrounds/graphiql/index.html +1144 -0
- package/playgrounds/scalar/index.html +19 -0
- package/src/ai/agent/agent.ts +222 -0
- package/src/ai/agent/index.ts +2 -0
- package/src/ai/agent/providers/anthropic.ts +113 -0
- package/src/ai/agent/providers/index.ts +62 -0
- package/src/ai/agent/providers/ollama.ts +128 -0
- package/src/ai/agent/providers/openai.ts +100 -0
- package/src/ai/agent/types.ts +65 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/mcp/create-server.ts +444 -0
- package/src/ai/mcp/index.ts +80 -0
- package/src/ai/mcp/instructions.ts +103 -0
- package/src/ai/tools/agent.ts +111 -0
- package/src/ai/tools/core.ts +486 -0
- package/src/ai/tools/query-data.ts +109 -0
- package/src/analyzeQuery/analyzers/fragmentAnalyzer.ts +29 -0
- package/src/analyzeQuery/analyzers/operationAnalyzer.ts +50 -0
- package/src/analyzeQuery/analyzers/selectionAnalyzer.ts +135 -0
- package/src/analyzeQuery/analyzers/variableAnalyzer.ts +17 -0
- package/src/analyzeQuery/depthLimit.ts +124 -0
- package/src/analyzeQuery/directiveUtils.ts +99 -0
- package/src/analyzeQuery/index.ts +66 -0
- package/src/analyzeQuery/resolveVariables.ts +394 -0
- package/src/analyzeQuery/typeUtils.ts +47 -0
- package/src/analyzeQuery/types.ts +57 -0
- package/src/analyzeQuery/valueExtractors.ts +96 -0
- package/src/authentication/duration.ts +50 -0
- package/src/authentication/index.ts +34 -0
- package/src/authentication/jwt.ts +220 -0
- package/src/authentication/paseto.ts +256 -0
- package/src/authentication/tokenRepository.ts +75 -0
- package/src/authentication/types.ts +78 -0
- package/src/cli/seedAuth.ts +51 -0
- package/src/cli/seedAuthArgs.ts +50 -0
- package/src/config/helpers/cronHelper.ts +29 -0
- package/src/config/helpers/index.ts +8 -0
- package/src/config/helpers/operationHelper.ts +146 -0
- package/src/config/helpers/queueHelper.ts +27 -0
- package/src/config/index.ts +315 -0
- package/src/config/types/ai.ts +35 -0
- package/src/config/types/auth.ts +147 -0
- package/src/config/types/configuration.ts +69 -0
- package/src/config/types/cron.ts +140 -0
- package/src/config/types/db.ts +256 -0
- package/src/config/types/index.ts +129 -0
- package/src/config/types/operation.ts +253 -0
- package/src/config/types/queue.ts +172 -0
- package/src/config/types/remote-rest.ts +28 -0
- package/src/config/types/remote-schema.ts +39 -0
- package/src/config/types/virtual-columns.ts +157 -0
- package/src/configuration/getSchemas/index.ts +82 -0
- package/src/configuration/getSchemas/mergeEntities/index.ts +221 -0
- package/src/configuration/getSchemas/type-definition-generator/index.ts +511 -0
- package/src/configuration/gql/buildExecute.ts +54 -0
- package/src/configuration/gql/gqlAuthOperations.ts +150 -0
- package/src/configuration/gql/handleGraphQLRequestFactory.ts +415 -0
- package/src/configuration/gql/handleGraphQLSubscriptionFactory.ts +249 -0
- package/src/configuration/index.ts +138 -0
- package/src/configuration/rest/generateOpenAPI.ts +361 -0
- package/src/configuration/rest/handleRESTRequestFactory.ts +335 -0
- package/src/configuration/rest/index.ts +167 -0
- package/src/configuration/rest/openApiErrors.ts +106 -0
- package/src/console/api.ts +270 -0
- package/src/cron/index.ts +251 -0
- package/src/databases/auth/auth-operations.ts +36 -0
- package/src/databases/auth/password.ts +4 -0
- package/src/databases/common.ts +642 -0
- package/src/databases/core/executor.ts +97 -0
- package/src/databases/core/function-mapping.ts +176 -0
- package/src/databases/core/identifier.ts +8 -0
- package/src/databases/core/query-builder.ts +47 -0
- package/src/databases/directives.ts +112 -0
- package/src/databases/engines/mssql/auth.ts +112 -0
- package/src/databases/engines/mssql/connection.ts +151 -0
- package/src/databases/engines/mssql/format.ts +23 -0
- package/src/databases/engines/mssql/getStructure.ts +112 -0
- package/src/databases/engines/mssql/getViews.ts +17 -0
- package/src/databases/engines/mssql/query/index.ts +306 -0
- package/src/databases/engines/mysql/auth.ts +100 -0
- package/src/databases/engines/mysql/connection.ts +100 -0
- package/src/databases/engines/mysql/format.ts +23 -0
- package/src/databases/engines/mysql/getStructure.ts +116 -0
- package/src/databases/engines/mysql/getViews.ts +20 -0
- package/src/databases/engines/mysql/query/index.ts +291 -0
- package/src/databases/engines/postgresql/auth.ts +98 -0
- package/src/databases/engines/postgresql/connection.ts +99 -0
- package/src/databases/engines/postgresql/format.ts +23 -0
- package/src/databases/engines/postgresql/getStructure.ts +149 -0
- package/src/databases/engines/postgresql/getViews.ts +20 -0
- package/src/databases/engines/postgresql/query/index.ts +291 -0
- package/src/databases/engines/shared/claims.ts +26 -0
- package/src/databases/engines/shared/types.ts +7 -0
- package/src/databases/high-level-operations.ts +272 -0
- package/src/databases/index.ts +28 -0
- package/src/databases/metadata/structure.ts +12 -0
- package/src/databases/schemaBuilder/convert.ts +121 -0
- package/src/databases/schemaBuilder/generateCreateTable/index.ts +133 -0
- package/src/databases/schemaBuilder/generateCreateView/index.ts +101 -0
- package/src/databases/schemaBuilder/generateInsert/index.ts +47 -0
- package/src/databases/schemaBuilder/generateSchemaCreation/index.ts +29 -0
- package/src/databases/schemaBuilder/mssqlToPostgres/convertView.ts +47 -0
- package/src/databases/schemaBuilder/utils.ts +17 -0
- package/src/databases/sqlTypeUtils.ts +91 -0
- package/src/databases/transformers/data-transformers.ts +128 -0
- package/src/databases/transformers/genResolverName.ts +18 -0
- package/src/index.ts +461 -0
- package/src/logging/index.ts +69 -0
- package/src/queues/kafka.ts +409 -0
- package/src/queues/rabbitmq.ts +331 -0
- package/src/remoteREST/index.ts +46 -0
- package/src/remoteREST/parse.ts +68 -0
- package/src/remoteREST/proxy.ts +92 -0
- package/src/remoteREST/transform.ts +121 -0
- package/src/remoteREST/types.ts +38 -0
- package/src/remoteSchemas/index.ts +48 -0
- package/src/remoteSchemas/introspect.ts +44 -0
- package/src/remoteSchemas/proxy.ts +146 -0
- package/src/remoteSchemas/transform.ts +210 -0
- package/src/remoteSchemas/types.ts +43 -0
- package/src/singletons/ai.ts +91 -0
- package/src/singletons/authentication.ts +13 -0
- package/src/singletons/cache/index.ts +4 -0
- package/src/singletons/cache/lruCacheStore.ts +34 -0
- package/src/singletons/cache/redisCacheStore.ts +81 -0
- package/src/singletons/cache/redisClient.ts +12 -0
- package/src/singletons/cache/registry.ts +51 -0
- package/src/singletons/cache/types.ts +7 -0
- package/src/singletons/cron.ts +21 -0
- package/src/singletons/databases.ts +68 -0
- package/src/singletons/env.ts +3 -0
- package/src/singletons/queues.ts +101 -0
- package/src/subscriptions/index.ts +20 -0
- package/src/subscriptions/strategies/database.ts +68 -0
- package/src/subscriptions/strategies/index.ts +38 -0
- package/src/subscriptions/strategies/queue.ts +61 -0
- package/src/subscriptions/types.ts +74 -0
- package/src/subscriptions/utils/polling.ts +119 -0
- package/src/types/common.ts +57 -0
- package/src/types/configuration.ts +52 -0
- package/src/types/db.ts +87 -0
- package/src/types/env.ts +137 -0
- package/src/types/resolver.ts +181 -0
- package/src/types/zod/ai.ts +8 -0
- package/src/types/zod/auth.ts +96 -0
- package/src/types/zod/configuration.ts +46 -0
- package/src/types/zod/cron.ts +35 -0
- package/src/types/zod/db.ts +146 -0
- package/src/types/zod/mcp.ts +8 -0
- package/src/types/zod/operation.ts +37 -0
- package/src/types/zod/queue.ts +182 -0
- package/src/types/zod/remoteREST.ts +8 -0
- package/src/types/zod/remoteSchema.ts +11 -0
- package/src/utils/benchmark.ts +13 -0
- package/src/utils/event-emitter.ts +217 -0
- package/src/utils/responses.ts +42 -0
- package/src/utils/safeJSONParse.ts +10 -0
- package/src/utils/selection.ts +35 -0
- package/src/utils/sessionVariables.ts +131 -0
- package/src/utils/writeSchema.ts +13 -0
- package/standalone.ts +32 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { isString } from "es-toolkit";
|
|
2
|
+
import { parse, specifiedRules, validate } from "graphql";
|
|
3
|
+
import { LRUCache } from "lru-cache";
|
|
4
|
+
|
|
5
|
+
import type { BunRequest } from "bun";
|
|
6
|
+
import type { DocumentNode, GraphQLError } from "graphql";
|
|
7
|
+
import type { AnalysisResult, SelectionAnalysis } from "../../analyzeQuery/types";
|
|
8
|
+
import type { GetGQLEntitiesReturn } from "../../configuration/getSchemas";
|
|
9
|
+
import type { MergedEntities } from "../../configuration/getSchemas/mergeEntities";
|
|
10
|
+
import type { Auth } from "../../types/configuration";
|
|
11
|
+
import type { SessionContext } from "../../utils/sessionVariables";
|
|
12
|
+
|
|
13
|
+
import { analyzeQuery } from "../../analyzeQuery";
|
|
14
|
+
import { depthLimitRule } from "../../analyzeQuery/depthLimit";
|
|
15
|
+
import { resolveVariableRef, resolveVariables } from "../../analyzeQuery/resolveVariables";
|
|
16
|
+
import { callStoredProcedure, executeQueryJSON, generateSQL } from "../../databases";
|
|
17
|
+
import { proxyRemoteField } from "../../remoteSchemas/proxy";
|
|
18
|
+
import { getAgent } from "../../singletons/ai";
|
|
19
|
+
import { databasesConnections, repositoryMap } from "../../singletons/databases";
|
|
20
|
+
import { env } from "../../singletons/env";
|
|
21
|
+
import { queueManager } from "../../singletons/queues";
|
|
22
|
+
import { EntitySource } from "../../types/resolver";
|
|
23
|
+
import { filterResultBySelection } from "../../utils/selection";
|
|
24
|
+
import { handleAuthMeQuery, handleAuthMutation } from "./gqlAuthOperations";
|
|
25
|
+
import { logger } from "../../logging";
|
|
26
|
+
|
|
27
|
+
// Handle GraphQL query
|
|
28
|
+
export const handleGraphQLRequestFactory = (
|
|
29
|
+
entities: MergedEntities,
|
|
30
|
+
gqlEntities: GetGQLEntitiesReturn,
|
|
31
|
+
auth: Auth | null = null,
|
|
32
|
+
) => {
|
|
33
|
+
// Mutation handlers by source type
|
|
34
|
+
const mutationHandlers: Partial<
|
|
35
|
+
Record<
|
|
36
|
+
EntitySource,
|
|
37
|
+
(
|
|
38
|
+
field: SelectionAnalysis,
|
|
39
|
+
variables: Record<string, unknown>,
|
|
40
|
+
queryAnalysis: AnalysisResult,
|
|
41
|
+
req?: BunRequest,
|
|
42
|
+
session?: SessionContext,
|
|
43
|
+
) => Promise<{ data: object }>
|
|
44
|
+
>
|
|
45
|
+
> = {
|
|
46
|
+
[EntitySource.QUEUE_PUBLISHER]: async (field, variables) => {
|
|
47
|
+
const data = resolveVariableRef(variables, field.arguments?.data);
|
|
48
|
+
|
|
49
|
+
const publisher = entities.queuesMap[field.name];
|
|
50
|
+
|
|
51
|
+
if (!publisher) {
|
|
52
|
+
throw new Error(`Queue publisher not found: ${field.name}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
data: {
|
|
57
|
+
[field.alias || field.name]: await queueManager?.sendMessage(
|
|
58
|
+
publisher.resolverName,
|
|
59
|
+
data?.toString() ?? "",
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
[EntitySource.AUTH]: (field, variables, _queryAnalysis, req, session) =>
|
|
66
|
+
handleAuthMutation(field, variables, auth, req, session),
|
|
67
|
+
|
|
68
|
+
[EntitySource.OPERATION]: async (field, variables) => {
|
|
69
|
+
const operation = entities.operations[field.name];
|
|
70
|
+
|
|
71
|
+
if (!operation?.handler) {
|
|
72
|
+
throw new Error(`Operation handler not found for: ${field.name}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const argumentsReplaced = Object.fromEntries(
|
|
76
|
+
Object.entries(field.arguments?.input ?? {}).map(([key, value]) => [
|
|
77
|
+
key,
|
|
78
|
+
resolveVariableRef(variables, value),
|
|
79
|
+
]),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const result = await operation.handler(
|
|
83
|
+
{
|
|
84
|
+
databases: databasesConnections,
|
|
85
|
+
gqlQuery: gql.handler,
|
|
86
|
+
queues: queueManager,
|
|
87
|
+
repository: repositoryMap,
|
|
88
|
+
},
|
|
89
|
+
argumentsReplaced,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Filter result based on requested fields
|
|
93
|
+
const filteredResult = filterResultBySelection(result, field.selections);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
data: {
|
|
97
|
+
[field.alias || field.name]: filteredResult,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
[EntitySource.STORED_PROCEDURE]: async (field, variables, queryAnalysis) => {
|
|
103
|
+
const sp = entities.mutationsMap[field.name];
|
|
104
|
+
|
|
105
|
+
if (!sp) {
|
|
106
|
+
throw new Error(`Stored procedure not found: ${field.name}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const argumentsReplaced = Object.fromEntries(
|
|
110
|
+
Object.entries(field.arguments ?? {}).map(([key, value]) => [
|
|
111
|
+
key,
|
|
112
|
+
resolveVariableRef(variables, value),
|
|
113
|
+
]),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const result = await callStoredProcedure(
|
|
117
|
+
sp,
|
|
118
|
+
queryAnalysis.operations[0].variables ?? [],
|
|
119
|
+
argumentsReplaced as Record<string, string | number | boolean | null>,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
data: {
|
|
124
|
+
[field.alias || field.name]: result,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
[EntitySource.REMOTE_SCHEMA]: async (field, variables, _queryAnalysis, req) => {
|
|
130
|
+
const entry = entities.remoteMutationsMap[field.name];
|
|
131
|
+
|
|
132
|
+
if (!entry) {
|
|
133
|
+
throw new Error(`Remote schema mutation not found: ${field.name}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const result = await proxyRemoteField(
|
|
137
|
+
field,
|
|
138
|
+
entry.remoteSchema,
|
|
139
|
+
entry.originalFieldName,
|
|
140
|
+
variables,
|
|
141
|
+
"mutation",
|
|
142
|
+
req,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
data: {
|
|
147
|
+
[field.alias || field.name]: result,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// Per-role LRU cache: keyed on raw query string, one entry per query enriched in
|
|
154
|
+
// place as the pipeline progresses (parse → validate → analyze). Caching validation
|
|
155
|
+
// is safe because the schema and depth rule are fixed for the factory's lifetime;
|
|
156
|
+
// if hot schema-reload is ever added, this cache must be dropped on reload.
|
|
157
|
+
interface CachedQuery {
|
|
158
|
+
document: DocumentNode;
|
|
159
|
+
validationErrors?: readonly GraphQLError[];
|
|
160
|
+
analysis?: AnalysisResult;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const queryCache = new LRUCache<string, CachedQuery>({ max: 1000 });
|
|
164
|
+
|
|
165
|
+
// undefined = unparseable query (never cached)
|
|
166
|
+
const getCacheEntry = (query: string): CachedQuery | undefined => {
|
|
167
|
+
const hit = queryCache.get(query);
|
|
168
|
+
if (hit) return hit;
|
|
169
|
+
try {
|
|
170
|
+
const entry: CachedQuery = { document: parse(query) };
|
|
171
|
+
queryCache.set(query, entry);
|
|
172
|
+
return entry;
|
|
173
|
+
} catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const isIntrospectionAST = (document: DocumentNode): boolean =>
|
|
179
|
+
document.definitions.some(
|
|
180
|
+
(def) =>
|
|
181
|
+
def.kind === "OperationDefinition" &&
|
|
182
|
+
def.selectionSet.selections.some(
|
|
183
|
+
(sel) => sel.kind === "Field" && sel.name.value === "__schema",
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const isNoDataAST = (document: DocumentNode): boolean =>
|
|
188
|
+
document.definitions.some(
|
|
189
|
+
(def) =>
|
|
190
|
+
def.kind === "OperationDefinition" &&
|
|
191
|
+
def.selectionSet.selections.some(
|
|
192
|
+
(sel) => sel.kind === "Field" && sel.name.value === "_no_data",
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const gql = {
|
|
197
|
+
// Check if the query is an introspection query (AST-based, not substring)
|
|
198
|
+
isIntrospectionQuery: (query: string) => {
|
|
199
|
+
const entry = getCacheEntry(query);
|
|
200
|
+
return entry ? isIntrospectionAST(entry.document) : false;
|
|
201
|
+
},
|
|
202
|
+
// Check if the query is a _no_data query (AST-based, not substring)
|
|
203
|
+
isNoDataQuery: (query: string) => {
|
|
204
|
+
const entry = getCacheEntry(query);
|
|
205
|
+
return entry ? isNoDataAST(entry.document) : false;
|
|
206
|
+
},
|
|
207
|
+
// Return the introspection result for clients like GraphiQL or Apollo Client
|
|
208
|
+
introspectionResult: { data: gqlEntities.introspection },
|
|
209
|
+
noDataResult: { data: { _no_data: "No data available" } },
|
|
210
|
+
hasErrors: (query: string) => {
|
|
211
|
+
const entry = getCacheEntry(query);
|
|
212
|
+
// Unparseable queries aren't cached; let parse surface the syntax error
|
|
213
|
+
const document = entry?.document ?? parse(query);
|
|
214
|
+
|
|
215
|
+
let validationErrors = entry?.validationErrors;
|
|
216
|
+
if (!validationErrors) {
|
|
217
|
+
const rules =
|
|
218
|
+
env.maxQueryDepth > 0
|
|
219
|
+
? [...specifiedRules, depthLimitRule(env.maxQueryDepth)]
|
|
220
|
+
: undefined; // undefined = use default specifiedRules
|
|
221
|
+
|
|
222
|
+
validationErrors = validate(gqlEntities.schema, document, rules);
|
|
223
|
+
if (entry) entry.validationErrors = validationErrors;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
hasErrors: validationErrors.length > 0,
|
|
228
|
+
validationErrors,
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
// Handle the GraphQL query
|
|
232
|
+
handler: async (
|
|
233
|
+
query: string | AnalysisResult,
|
|
234
|
+
variables: Record<string, unknown> = {},
|
|
235
|
+
req?: BunRequest,
|
|
236
|
+
session?: SessionContext,
|
|
237
|
+
// oxlint-disable-next-line typescript/no-explicit-any
|
|
238
|
+
): Promise<{ data: any }> => {
|
|
239
|
+
const log = logger("graphql").child({ role: session?.role });
|
|
240
|
+
const startTime = Bun.nanoseconds();
|
|
241
|
+
|
|
242
|
+
// Reuse cached analysis on repeated identical queries
|
|
243
|
+
const entry = isString(query) ? getCacheEntry(query) : undefined;
|
|
244
|
+
let queryAnalysis: AnalysisResult;
|
|
245
|
+
if (entry?.analysis) {
|
|
246
|
+
queryAnalysis = entry.analysis;
|
|
247
|
+
} else {
|
|
248
|
+
queryAnalysis = isString(query) ? analyzeQuery(query, entities, gqlEntities.schema) : query;
|
|
249
|
+
if (entry) entry.analysis = queryAnalysis;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (queryAnalysis.operations.length === 0) {
|
|
253
|
+
return { data: {} };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const operation = queryAnalysis.operations[0];
|
|
257
|
+
log.debug(
|
|
258
|
+
{
|
|
259
|
+
operation: operation.operation,
|
|
260
|
+
name: operation.name,
|
|
261
|
+
fieldCount: operation.fields?.length,
|
|
262
|
+
queryLength: isString(query) ? query.length : undefined,
|
|
263
|
+
},
|
|
264
|
+
"graphql request",
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
// Single pass: validate, flatten object vars, resolve field args + session vars
|
|
268
|
+
// Returns an immutable ResolvedOperation — original operation is not mutated
|
|
269
|
+
const resolved = resolveVariables(operation, variables, session);
|
|
270
|
+
|
|
271
|
+
if (operation.operation === "query") {
|
|
272
|
+
// Separate auth fields, remote schema fields, and table fields
|
|
273
|
+
const authFields = resolved.fields.filter((field) => field.source === EntitySource.AUTH);
|
|
274
|
+
const remoteFields = resolved.fields.filter(
|
|
275
|
+
(field) => field.source === EntitySource.REMOTE_SCHEMA,
|
|
276
|
+
);
|
|
277
|
+
const aiFields = resolved.fields.filter((field) => field.source === EntitySource.AI);
|
|
278
|
+
const tableFields = resolved.fields.filter(
|
|
279
|
+
(field) =>
|
|
280
|
+
field.source !== EntitySource.AUTH &&
|
|
281
|
+
field.source !== EntitySource.REMOTE_SCHEMA &&
|
|
282
|
+
field.source !== EntitySource.AI,
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Handle auth queries (e.g. auth_me)
|
|
286
|
+
let authData: Record<string, unknown> = {};
|
|
287
|
+
for (const field of authFields) {
|
|
288
|
+
Object.assign(authData, handleAuthMeQuery(field, session));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Handle remote schema queries in parallel
|
|
292
|
+
let remoteData: Record<string, unknown> = {};
|
|
293
|
+
if (remoteFields.length > 0) {
|
|
294
|
+
const remoteResults = await Promise.all(
|
|
295
|
+
remoteFields.map(async (field) => {
|
|
296
|
+
const entry = entities.remoteQueriesMap[field.name];
|
|
297
|
+
if (!entry) {
|
|
298
|
+
throw new Error(`Remote schema query not found: ${field.name}`);
|
|
299
|
+
}
|
|
300
|
+
const result = await proxyRemoteField(
|
|
301
|
+
field,
|
|
302
|
+
entry.remoteSchema,
|
|
303
|
+
entry.originalFieldName,
|
|
304
|
+
resolved.allVariables,
|
|
305
|
+
"query",
|
|
306
|
+
req,
|
|
307
|
+
);
|
|
308
|
+
return { [field.alias || field.name]: result };
|
|
309
|
+
}),
|
|
310
|
+
);
|
|
311
|
+
remoteData = remoteResults.reduce((acc, curr) => Object.assign(acc, curr), {});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Handle AI agent queries (admin-only `ask` field)
|
|
315
|
+
let aiData: Record<string, unknown> = {};
|
|
316
|
+
for (const field of aiFields) {
|
|
317
|
+
const alias = field.alias || field.name;
|
|
318
|
+
const prompt = field.arguments?.prompt;
|
|
319
|
+
aiData[alias] = await getAgent()(String(prompt ?? ""));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Skip SQL generation if there are no table fields
|
|
323
|
+
if (tableFields.length === 0) {
|
|
324
|
+
log.debug(
|
|
325
|
+
{ durationMs: (Bun.nanoseconds() - startTime) / 1e6 },
|
|
326
|
+
"graphql request completed (no table fields)",
|
|
327
|
+
);
|
|
328
|
+
return { data: { ...authData, ...remoteData, ...aiData } };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const tableQueryAnalysis = {
|
|
332
|
+
...queryAnalysis,
|
|
333
|
+
operations: [
|
|
334
|
+
{
|
|
335
|
+
...operation,
|
|
336
|
+
fields: tableFields,
|
|
337
|
+
variables: resolved.variables,
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const sqlQueries = generateSQL(entities, tableQueryAnalysis, resolved.allVariables);
|
|
343
|
+
|
|
344
|
+
const data = await Promise.all<object>(
|
|
345
|
+
sqlQueries.map(([db, query]) =>
|
|
346
|
+
executeQueryJSON(
|
|
347
|
+
query,
|
|
348
|
+
db,
|
|
349
|
+
resolved.variables,
|
|
350
|
+
resolved.allVariables as Record<string, string | number | boolean | null>,
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
log.debug(
|
|
356
|
+
{ durationMs: (Bun.nanoseconds() - startTime) / 1e6, dbCount: sqlQueries.length },
|
|
357
|
+
"graphql request completed",
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
...(env.queryOnResponse
|
|
362
|
+
? {
|
|
363
|
+
sqlQueries: sqlQueries.map(([db, query]) => ({
|
|
364
|
+
db: db.name,
|
|
365
|
+
query,
|
|
366
|
+
})),
|
|
367
|
+
}
|
|
368
|
+
: {}),
|
|
369
|
+
data: data.reduce((acc, curr) => Object.assign(acc, curr), {
|
|
370
|
+
...authData,
|
|
371
|
+
...remoteData,
|
|
372
|
+
...aiData,
|
|
373
|
+
}),
|
|
374
|
+
};
|
|
375
|
+
} else if (operation.operation === "mutation") {
|
|
376
|
+
// Route mutation to the appropriate handler based on field source
|
|
377
|
+
let results: Record<string, object> = {};
|
|
378
|
+
|
|
379
|
+
for await (const field of resolved.fields) {
|
|
380
|
+
const source = field.source;
|
|
381
|
+
|
|
382
|
+
if (source && mutationHandlers[source]) {
|
|
383
|
+
const result = await mutationHandlers[source]!(
|
|
384
|
+
field,
|
|
385
|
+
resolved.allVariables,
|
|
386
|
+
queryAnalysis,
|
|
387
|
+
req,
|
|
388
|
+
session,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
results = {
|
|
392
|
+
...results,
|
|
393
|
+
...result.data,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
log.debug(
|
|
399
|
+
{ durationMs: (Bun.nanoseconds() - startTime) / 1e6 },
|
|
400
|
+
"graphql request completed",
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
return {
|
|
404
|
+
data: results,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return { data: {} };
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
return gql;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export type HandleGraphQLRequest = ReturnType<typeof handleGraphQLRequestFactory>;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import type { ServerWebSocket, WebSocketHandler } from "bun";
|
|
2
|
+
import type { AnalyzedConfiguration } from "../../configuration";
|
|
3
|
+
import type { SubscriptionContext } from "../../subscriptions";
|
|
4
|
+
import type { SessionContext } from "../../utils/sessionVariables";
|
|
5
|
+
|
|
6
|
+
import { analyzeQuery } from "../../analyzeQuery";
|
|
7
|
+
import { resolveVariables } from "../../analyzeQuery/resolveVariables";
|
|
8
|
+
import { getTokenService } from "../../singletons/authentication";
|
|
9
|
+
import { createSubscriptionStrategyRegistry, getStrategyForSource } from "../../subscriptions";
|
|
10
|
+
import { createQueryEventEmitter } from "../../utils/event-emitter";
|
|
11
|
+
import { logger } from "../../logging";
|
|
12
|
+
|
|
13
|
+
export const queryEventEmitter = createQueryEventEmitter();
|
|
14
|
+
|
|
15
|
+
// Create the strategy registry once at module load
|
|
16
|
+
const strategyRegistry = createSubscriptionStrategyRegistry();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Handle GraphQL subscription messages
|
|
20
|
+
*
|
|
21
|
+
* This factory creates a WebSocket message handler that:
|
|
22
|
+
* 1. Handles the graphql-ws protocol (connection_init, ping, subscribe, complete)
|
|
23
|
+
* 2. Delegates subscription logic to source-specific strategies
|
|
24
|
+
*/
|
|
25
|
+
const handleGraphQLSubscriptionFactory = (
|
|
26
|
+
roles: AnalyzedConfiguration["roles"],
|
|
27
|
+
subscriptionMapping: Map<ServerWebSocket<unknown>, SessionContext>,
|
|
28
|
+
activeSubscriptions: Map<
|
|
29
|
+
string,
|
|
30
|
+
{
|
|
31
|
+
ws: ServerWebSocket<unknown>;
|
|
32
|
+
operationName: string;
|
|
33
|
+
cleanup?: () => void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
>,
|
|
36
|
+
) => {
|
|
37
|
+
return async (ws: ServerWebSocket<unknown>, body: string) => {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(body);
|
|
40
|
+
const { id, type, payload } = parsed;
|
|
41
|
+
|
|
42
|
+
// Validate message format
|
|
43
|
+
if (!type) {
|
|
44
|
+
ws.send(
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
type: "connection_error",
|
|
47
|
+
payload: { message: "Message must have a 'type' field" },
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Handle connection_init
|
|
54
|
+
if (type === "connection_init") {
|
|
55
|
+
const session = await getTokenService().verifyTokenAndGetSession(
|
|
56
|
+
payload?.Authorization,
|
|
57
|
+
payload?.headers?.["x-admin-secret"],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
subscriptionMapping.set(ws, session);
|
|
61
|
+
|
|
62
|
+
logger("subscriptions").debug({ role: session.role }, "client connected");
|
|
63
|
+
|
|
64
|
+
ws.send(
|
|
65
|
+
JSON.stringify({
|
|
66
|
+
type: "connection_ack",
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Handle ping
|
|
73
|
+
if (type === "ping") {
|
|
74
|
+
ws.send(
|
|
75
|
+
JSON.stringify({
|
|
76
|
+
type: "pong",
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Handle subscribe
|
|
83
|
+
if (type === "subscribe") {
|
|
84
|
+
if (!id) {
|
|
85
|
+
ws.send(
|
|
86
|
+
JSON.stringify({
|
|
87
|
+
type: "connection_error",
|
|
88
|
+
payload: { message: "Subscribe message must have an 'id' field" },
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { query, variables, operationName } = payload ?? {};
|
|
95
|
+
const session = subscriptionMapping.get(ws)!;
|
|
96
|
+
const schemaEntity = roles[session.role!];
|
|
97
|
+
|
|
98
|
+
// Validate query
|
|
99
|
+
const { hasErrors, validationErrors } = schemaEntity.handlers.gql.hasErrors(query);
|
|
100
|
+
|
|
101
|
+
if (hasErrors) {
|
|
102
|
+
queryEventEmitter.sendErrorToSingleClient(ws, id, validationErrors);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Analyze the query
|
|
107
|
+
const analysis = analyzeQuery(query, schemaEntity, schemaEntity.schema);
|
|
108
|
+
|
|
109
|
+
const operation = analysis.operations[0];
|
|
110
|
+
const field = operation.fields[0];
|
|
111
|
+
|
|
112
|
+
// Get the appropriate strategy based on field source
|
|
113
|
+
const strategy = getStrategyForSource(strategyRegistry, field?.source);
|
|
114
|
+
|
|
115
|
+
if (!strategy) {
|
|
116
|
+
ws.send(
|
|
117
|
+
JSON.stringify({
|
|
118
|
+
id,
|
|
119
|
+
type: "error",
|
|
120
|
+
payload: [
|
|
121
|
+
{
|
|
122
|
+
message: `Unsupported subscription source: ${field?.source}`,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Resolve variables: flatten object-type vars and replace $session.* references
|
|
131
|
+
let resolved;
|
|
132
|
+
try {
|
|
133
|
+
resolved = resolveVariables(operation, variables || {}, session);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
ws.send(
|
|
136
|
+
JSON.stringify({
|
|
137
|
+
id,
|
|
138
|
+
type: "error",
|
|
139
|
+
payload: [
|
|
140
|
+
{
|
|
141
|
+
message: error instanceof Error ? error.message : "Variable resolution failed",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Build context for the strategy
|
|
150
|
+
const context: SubscriptionContext = {
|
|
151
|
+
ws,
|
|
152
|
+
subscriptionId: id,
|
|
153
|
+
analysis,
|
|
154
|
+
field: resolved.fields[0],
|
|
155
|
+
variableDefinitions: resolved.variables,
|
|
156
|
+
variables: resolved.allVariables,
|
|
157
|
+
schemaEntity,
|
|
158
|
+
eventEmitter: queryEventEmitter,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Execute the strategy (handles connection registration internally)
|
|
162
|
+
const result = await strategy.subscribe(context);
|
|
163
|
+
|
|
164
|
+
// Store the subscription only if it's a new connection
|
|
165
|
+
if (!result.alreadyExists) {
|
|
166
|
+
logger("subscriptions").debug(
|
|
167
|
+
{ operation: operationName || operation.name, subscriptionId: id },
|
|
168
|
+
"subscribed",
|
|
169
|
+
);
|
|
170
|
+
activeSubscriptions.set(id, {
|
|
171
|
+
ws,
|
|
172
|
+
operationName: operationName || operation.name!,
|
|
173
|
+
cleanup: result.cleanup,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Handle complete
|
|
179
|
+
if (type === "complete") {
|
|
180
|
+
if (!id) {
|
|
181
|
+
ws.send(
|
|
182
|
+
JSON.stringify({
|
|
183
|
+
type: "connection_error",
|
|
184
|
+
payload: { message: "Complete message must have an 'id' field" },
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const subscription = activeSubscriptions.get(id);
|
|
191
|
+
if (subscription) {
|
|
192
|
+
logger("subscriptions").debug({ subscriptionId: id }, "unsubscribed");
|
|
193
|
+
// Call cleanup if available
|
|
194
|
+
if (subscription.cleanup) {
|
|
195
|
+
await subscription.cleanup();
|
|
196
|
+
}
|
|
197
|
+
activeSubscriptions.delete(id);
|
|
198
|
+
}
|
|
199
|
+
queryEventEmitter.removeSubscription(ws, id);
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error instanceof SyntaxError) {
|
|
203
|
+
logger("subscriptions").warn({ err: error }, "syntax error in subscription message");
|
|
204
|
+
} else {
|
|
205
|
+
logger("subscriptions").error({ err: error }, "subscription handler error");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const websocketHandlerFactory = (
|
|
214
|
+
roles: AnalyzedConfiguration["roles"],
|
|
215
|
+
): WebSocketHandler<unknown> => {
|
|
216
|
+
const subscriptionMapping: Map<ServerWebSocket<unknown>, SessionContext> = new Map();
|
|
217
|
+
const activeSubscriptions: Map<
|
|
218
|
+
string,
|
|
219
|
+
{
|
|
220
|
+
ws: ServerWebSocket<unknown>;
|
|
221
|
+
operationName: string;
|
|
222
|
+
cleanup?: () => void | Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
> = new Map();
|
|
225
|
+
|
|
226
|
+
const handleGraphQLSubscription = handleGraphQLSubscriptionFactory(
|
|
227
|
+
roles,
|
|
228
|
+
subscriptionMapping,
|
|
229
|
+
activeSubscriptions,
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
async message(ws, message) {
|
|
234
|
+
handleGraphQLSubscription(ws, message as string);
|
|
235
|
+
},
|
|
236
|
+
close(ws) {
|
|
237
|
+
logger("subscriptions").debug("client disconnected");
|
|
238
|
+
// Clean up all subscriptions for this WebSocket
|
|
239
|
+
for (const [subscriptionId, subscription] of activeSubscriptions.entries()) {
|
|
240
|
+
if (subscription.ws === ws) {
|
|
241
|
+
subscription.cleanup?.();
|
|
242
|
+
activeSubscriptions.delete(subscriptionId);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
queryEventEmitter.removeConnection(ws);
|
|
246
|
+
subscriptionMapping.delete(ws);
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
};
|