@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
package/src/ai/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ask, createAgent } from "./agent";
|
|
2
|
+
export type { AgentConfig } from "./agent";
|
|
3
|
+
|
|
4
|
+
export { createMCPRoutes } from "./mcp";
|
|
5
|
+
export type { CreateMCPRoutesOptions } from "./mcp";
|
|
6
|
+
|
|
7
|
+
export { buildAgentTools } from "./tools/agent";
|
|
8
|
+
export type { RoleEntities } from "./tools/core";
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import type { CallToolResult, ReadResourceResult } from "@modelcontextprotocol/server";
|
|
5
|
+
import type { AnalyzedConfiguration } from "../../configuration";
|
|
6
|
+
|
|
7
|
+
import { GRAPHORIA_MCP_INSTRUCTIONS } from "./instructions";
|
|
8
|
+
import {
|
|
9
|
+
describeEntityCore,
|
|
10
|
+
ENTITY_KINDS,
|
|
11
|
+
executeGraphqlCore,
|
|
12
|
+
listEntitiesCore,
|
|
13
|
+
makeValidateQuery,
|
|
14
|
+
synthesizeRequest,
|
|
15
|
+
} from "../tools/core";
|
|
16
|
+
import { logger } from "../../logging";
|
|
17
|
+
import { buildStructuredQuery, queryDataSchema } from "../tools/query-data";
|
|
18
|
+
|
|
19
|
+
export type CreateMcpServerOptions = {
|
|
20
|
+
name?: string;
|
|
21
|
+
version?: string;
|
|
22
|
+
maxQueryDepth?: number;
|
|
23
|
+
graphqlEnabled?: boolean;
|
|
24
|
+
restEnabled?: boolean;
|
|
25
|
+
disabledTools?: string[];
|
|
26
|
+
disabledResources?: string[];
|
|
27
|
+
disabledPrompts?: string[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const ANONYMOUS_ROLE = "anonymous";
|
|
31
|
+
|
|
32
|
+
const errorResult = (text: string): CallToolResult => ({
|
|
33
|
+
content: [{ type: "text", text }],
|
|
34
|
+
isError: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const jsonResult = (value: unknown): CallToolResult => ({
|
|
38
|
+
content: [{ type: "text", text: JSON.stringify(value, null, 2) }],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const createMcpServer = (
|
|
42
|
+
analyzedConfiguration: AnalyzedConfiguration,
|
|
43
|
+
options: CreateMcpServerOptions = {},
|
|
44
|
+
) => {
|
|
45
|
+
const {
|
|
46
|
+
name = "graphoria-mcp-server",
|
|
47
|
+
version = "1.0.0",
|
|
48
|
+
maxQueryDepth,
|
|
49
|
+
graphqlEnabled,
|
|
50
|
+
restEnabled,
|
|
51
|
+
disabledTools = [],
|
|
52
|
+
disabledResources = [],
|
|
53
|
+
disabledPrompts = [],
|
|
54
|
+
} = options;
|
|
55
|
+
|
|
56
|
+
const disabledToolSet = new Set(disabledTools);
|
|
57
|
+
if (graphqlEnabled === false) disabledToolSet.add("graphql_execute");
|
|
58
|
+
if (restEnabled === false) disabledToolSet.add("rest_execute");
|
|
59
|
+
const disabledResourceSet = new Set(disabledResources);
|
|
60
|
+
const disabledPromptSet = new Set(disabledPrompts);
|
|
61
|
+
|
|
62
|
+
const server = new McpServer(
|
|
63
|
+
{ name, version },
|
|
64
|
+
{
|
|
65
|
+
capabilities: { logging: {} },
|
|
66
|
+
instructions: GRAPHORIA_MCP_INSTRUCTIONS,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const role = analyzedConfiguration.roles[ANONYMOUS_ROLE];
|
|
71
|
+
if (!role) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`MCP server requires the '${ANONYMOUS_ROLE}' role to be present in the configuration.`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const { handlers, typeDefs, introspection } = role;
|
|
77
|
+
|
|
78
|
+
const validateQuery = makeValidateQuery(role, maxQueryDepth);
|
|
79
|
+
|
|
80
|
+
const registerToolIfEnabled: typeof server.registerTool = ((
|
|
81
|
+
toolName: string,
|
|
82
|
+
...rest: unknown[]
|
|
83
|
+
) => {
|
|
84
|
+
if (disabledToolSet.has(toolName)) return null;
|
|
85
|
+
return (server.registerTool as unknown as (...a: unknown[]) => unknown)(toolName, ...rest);
|
|
86
|
+
}) as typeof server.registerTool;
|
|
87
|
+
|
|
88
|
+
const registerResourceIfEnabled: typeof server.registerResource = ((
|
|
89
|
+
resourceName: string,
|
|
90
|
+
uri: string,
|
|
91
|
+
...rest: unknown[]
|
|
92
|
+
) => {
|
|
93
|
+
if (disabledResourceSet.has(uri) || disabledResourceSet.has(resourceName)) return null;
|
|
94
|
+
return (server.registerResource as unknown as (...a: unknown[]) => unknown)(
|
|
95
|
+
resourceName,
|
|
96
|
+
uri,
|
|
97
|
+
...rest,
|
|
98
|
+
);
|
|
99
|
+
}) as typeof server.registerResource;
|
|
100
|
+
|
|
101
|
+
const registerPromptIfEnabled: typeof server.registerPrompt = ((
|
|
102
|
+
promptName: string,
|
|
103
|
+
...rest: unknown[]
|
|
104
|
+
) => {
|
|
105
|
+
if (disabledPromptSet.has(promptName)) return null;
|
|
106
|
+
return (server.registerPrompt as unknown as (...a: unknown[]) => unknown)(promptName, ...rest);
|
|
107
|
+
}) as typeof server.registerPrompt;
|
|
108
|
+
|
|
109
|
+
// ----- Tools -----
|
|
110
|
+
|
|
111
|
+
registerToolIfEnabled(
|
|
112
|
+
"query_data",
|
|
113
|
+
{
|
|
114
|
+
title: "Query Data (Structured JSON)",
|
|
115
|
+
description:
|
|
116
|
+
"Query data using structured JSON instead of raw GraphQL. PREFERRED over graphql_execute for list and aggregate queries — simpler, less error-prone. The server builds the correct GraphQL query internally from your JSON input.",
|
|
117
|
+
inputSchema: queryDataSchema,
|
|
118
|
+
},
|
|
119
|
+
async (args): Promise<CallToolResult> => {
|
|
120
|
+
try {
|
|
121
|
+
const query = buildStructuredQuery(args as Parameters<typeof buildStructuredQuery>[0]);
|
|
122
|
+
const outcome = await executeGraphqlCore(role, validateQuery, {
|
|
123
|
+
query,
|
|
124
|
+
});
|
|
125
|
+
switch (outcome.kind) {
|
|
126
|
+
case "non_query":
|
|
127
|
+
return errorResult("Internal: built query is not a query.");
|
|
128
|
+
case "validation":
|
|
129
|
+
return jsonResult({ data: null, errors: outcome.errors });
|
|
130
|
+
case "error":
|
|
131
|
+
return errorResult(`Error executing query: ${outcome.message}`);
|
|
132
|
+
case "ok":
|
|
133
|
+
return jsonResult(outcome.result);
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return errorResult(
|
|
137
|
+
`Error building query: ${error instanceof Error ? error.message : String(error)}`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
registerToolIfEnabled(
|
|
144
|
+
"graphql_execute",
|
|
145
|
+
{
|
|
146
|
+
title: "Execute GraphQL Query",
|
|
147
|
+
description:
|
|
148
|
+
"Executes a GraphQL query against the anonymous-role schema. Mutations and subscriptions are rejected. Returns { data, errors } JSON.",
|
|
149
|
+
inputSchema: z.object({
|
|
150
|
+
query: z.string().describe("GraphQL query string"),
|
|
151
|
+
variables: z.record(z.string(), z.unknown()).optional().describe("GraphQL variables map"),
|
|
152
|
+
}),
|
|
153
|
+
},
|
|
154
|
+
async ({ query, variables }): Promise<CallToolResult> => {
|
|
155
|
+
const outcome = await executeGraphqlCore(role, validateQuery, {
|
|
156
|
+
query,
|
|
157
|
+
variables,
|
|
158
|
+
});
|
|
159
|
+
switch (outcome.kind) {
|
|
160
|
+
case "non_query":
|
|
161
|
+
return errorResult(
|
|
162
|
+
"Only `query` operations are allowed via MCP. Mutations and subscriptions are rejected.",
|
|
163
|
+
);
|
|
164
|
+
case "validation":
|
|
165
|
+
return jsonResult({ data: null, errors: outcome.errors });
|
|
166
|
+
case "error":
|
|
167
|
+
return errorResult(`Error executing query: ${outcome.message}`);
|
|
168
|
+
case "ok":
|
|
169
|
+
return jsonResult(outcome.result);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
registerToolIfEnabled(
|
|
175
|
+
"graphql_validate",
|
|
176
|
+
{
|
|
177
|
+
title: "Validate GraphQL Query",
|
|
178
|
+
description:
|
|
179
|
+
"Validates a GraphQL query against the anonymous-role schema without executing it. Returns { valid, errors }.",
|
|
180
|
+
inputSchema: z.object({
|
|
181
|
+
query: z.string().describe("GraphQL query string"),
|
|
182
|
+
}),
|
|
183
|
+
},
|
|
184
|
+
async ({ query }): Promise<CallToolResult> => {
|
|
185
|
+
try {
|
|
186
|
+
const { hasErrors, validationErrors } = validateQuery(query);
|
|
187
|
+
return jsonResult({
|
|
188
|
+
valid: !hasErrors,
|
|
189
|
+
errors: validationErrors.map((e) => ({
|
|
190
|
+
message: e.message,
|
|
191
|
+
locations: e.locations,
|
|
192
|
+
})),
|
|
193
|
+
});
|
|
194
|
+
} catch (error) {
|
|
195
|
+
return jsonResult({
|
|
196
|
+
valid: false,
|
|
197
|
+
errors: [
|
|
198
|
+
{
|
|
199
|
+
message: error instanceof Error ? error.message : String(error),
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
registerToolIfEnabled(
|
|
208
|
+
"list_entities",
|
|
209
|
+
{
|
|
210
|
+
title: "List Entities",
|
|
211
|
+
description:
|
|
212
|
+
"Lists entities exposed to the anonymous role: tables, operations, remote schemas, remote REST APIs, stored procedures, queue publishers. Requires at least one of `kind` or `search` — calling with no arguments is rejected to keep result sets focused. Use `kind` to browse a category, `search` to find by name fragment, or both together.",
|
|
213
|
+
inputSchema: z
|
|
214
|
+
.object({
|
|
215
|
+
kind: z
|
|
216
|
+
.enum(ENTITY_KINDS)
|
|
217
|
+
.optional()
|
|
218
|
+
.describe("Filter to one category. Required unless `search` is provided."),
|
|
219
|
+
search: z
|
|
220
|
+
.string()
|
|
221
|
+
.min(1)
|
|
222
|
+
.optional()
|
|
223
|
+
.describe(
|
|
224
|
+
"Case-insensitive substring match. For tables, matches against resolverName, raw schema/table name, AND tableDescription — useful when the DB has cryptic names but rich descriptions. For operations, matches name and description. Required unless `kind` is provided.",
|
|
225
|
+
),
|
|
226
|
+
})
|
|
227
|
+
.refine((v) => v.kind !== undefined || v.search !== undefined, {
|
|
228
|
+
message:
|
|
229
|
+
'list_entities requires at least one of `kind` or `search`. Pick a kind to browse a category (e.g. kind: "table") or supply a search term (e.g. search: "user").',
|
|
230
|
+
}),
|
|
231
|
+
},
|
|
232
|
+
async ({ kind, search }): Promise<CallToolResult> => {
|
|
233
|
+
try {
|
|
234
|
+
if (kind === undefined && (search === undefined || search === "")) {
|
|
235
|
+
return errorResult(
|
|
236
|
+
'list_entities requires at least one of `kind` or `search`. Pick a kind (e.g. kind: "table") or supply a search term.',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return jsonResult(listEntitiesCore(role, { kind, search }));
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return errorResult(
|
|
242
|
+
`Error listing entities: ${error instanceof Error ? error.message : String(error)}`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
registerToolIfEnabled(
|
|
249
|
+
"describe_entity",
|
|
250
|
+
{
|
|
251
|
+
title: "Describe Entity",
|
|
252
|
+
description:
|
|
253
|
+
"Returns detailed information about an entity. For tables, includes columns, relationships, the generated GraphQL list-field and _aggregate-field signatures, and ready-to-run example queries (list / filter / aggregate) using this table's real column names. For remote schemas/REST, includes their imported SDL/OpenAPI shape.",
|
|
254
|
+
inputSchema: z.object({
|
|
255
|
+
name: z.string().describe("Entity name (e.g. resolverName for tables)"),
|
|
256
|
+
kind: z.enum(ENTITY_KINDS).optional(),
|
|
257
|
+
}),
|
|
258
|
+
},
|
|
259
|
+
async ({ name, kind }): Promise<CallToolResult> => {
|
|
260
|
+
try {
|
|
261
|
+
const result = describeEntityCore(role, { name, kind });
|
|
262
|
+
if (!result)
|
|
263
|
+
return errorResult(kind ? `${kind} '${name}' not found.` : `Entity '${name}' not found.`);
|
|
264
|
+
return jsonResult(result);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return errorResult(
|
|
267
|
+
`Error describing entity: ${error instanceof Error ? error.message : String(error)}`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
registerToolIfEnabled(
|
|
274
|
+
"rest_execute",
|
|
275
|
+
{
|
|
276
|
+
title: "Execute REST Request",
|
|
277
|
+
description:
|
|
278
|
+
"Executes a request against the anonymous-role REST handler. `path` is the path under the REST prefix (e.g. /users/123). Body is auto-JSON-stringified.",
|
|
279
|
+
inputSchema: z.object({
|
|
280
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).default("GET"),
|
|
281
|
+
path: z.string().describe("Path relative to the REST prefix"),
|
|
282
|
+
query: z.record(z.string(), z.string()).optional(),
|
|
283
|
+
body: z.unknown().optional(),
|
|
284
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
285
|
+
}),
|
|
286
|
+
},
|
|
287
|
+
async ({ method, path, query, body, headers }): Promise<CallToolResult> => {
|
|
288
|
+
try {
|
|
289
|
+
const url = new URL(path, "http://mcp.local");
|
|
290
|
+
if (query) {
|
|
291
|
+
for (const [k, v] of Object.entries(query)) {
|
|
292
|
+
url.searchParams.append(k, v);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const init: RequestInit & { body?: BodyInit | null } = {
|
|
297
|
+
method,
|
|
298
|
+
headers: {
|
|
299
|
+
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
|
300
|
+
...(headers ?? {}),
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
if (body !== undefined) {
|
|
304
|
+
init.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const req = synthesizeRequest(url.toString(), init);
|
|
308
|
+
const response = await handlers.rest.handler(url, url.pathname, method, req);
|
|
309
|
+
|
|
310
|
+
const text = await response.text();
|
|
311
|
+
let parsedBody: unknown = text;
|
|
312
|
+
try {
|
|
313
|
+
parsedBody = JSON.parse(text);
|
|
314
|
+
} catch {
|
|
315
|
+
// Keep as text
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const headersOut: Record<string, string> = {};
|
|
319
|
+
response.headers.forEach((v, k) => {
|
|
320
|
+
headersOut[k] = v;
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return jsonResult({
|
|
324
|
+
status: response.status,
|
|
325
|
+
headers: headersOut,
|
|
326
|
+
body: parsedBody,
|
|
327
|
+
});
|
|
328
|
+
} catch (error) {
|
|
329
|
+
return errorResult(
|
|
330
|
+
`Error executing REST request: ${error instanceof Error ? error.message : String(error)}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// ----- Resources -----
|
|
337
|
+
|
|
338
|
+
registerResourceIfEnabled(
|
|
339
|
+
"graphql-schema",
|
|
340
|
+
"graphql://schema",
|
|
341
|
+
{
|
|
342
|
+
title: "GraphQL Schema (SDL)",
|
|
343
|
+
description: "Anonymous-role GraphQL schema in SDL format.",
|
|
344
|
+
mimeType: "text/plain",
|
|
345
|
+
},
|
|
346
|
+
async (uri): Promise<ReadResourceResult> => ({
|
|
347
|
+
contents: [{ uri: uri.href, mimeType: "text/plain", text: typeDefs }],
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
registerResourceIfEnabled(
|
|
352
|
+
"graphql-introspection",
|
|
353
|
+
"graphql://introspection",
|
|
354
|
+
{
|
|
355
|
+
title: "GraphQL Introspection",
|
|
356
|
+
description: "Anonymous-role GraphQL introspection result (JSON).",
|
|
357
|
+
mimeType: "application/json",
|
|
358
|
+
},
|
|
359
|
+
async (uri): Promise<ReadResourceResult> => ({
|
|
360
|
+
contents: [
|
|
361
|
+
{
|
|
362
|
+
uri: uri.href,
|
|
363
|
+
mimeType: "application/json",
|
|
364
|
+
text: JSON.stringify(introspection, null, 2),
|
|
365
|
+
},
|
|
366
|
+
],
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
registerResourceIfEnabled(
|
|
371
|
+
"openapi-spec",
|
|
372
|
+
"openapi://spec",
|
|
373
|
+
{
|
|
374
|
+
title: "OpenAPI Spec",
|
|
375
|
+
description: "Unified OpenAPI specification (operations + remote-REST).",
|
|
376
|
+
mimeType: "application/json",
|
|
377
|
+
},
|
|
378
|
+
async (uri): Promise<ReadResourceResult> => ({
|
|
379
|
+
contents: [
|
|
380
|
+
{
|
|
381
|
+
uri: uri.href,
|
|
382
|
+
mimeType: "application/json",
|
|
383
|
+
text: JSON.stringify(analyzedConfiguration.openapi, null, 2),
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
}),
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
// ----- Prompts -----
|
|
390
|
+
|
|
391
|
+
registerPromptIfEnabled(
|
|
392
|
+
"db_query",
|
|
393
|
+
{
|
|
394
|
+
title: "Database Query",
|
|
395
|
+
description:
|
|
396
|
+
"Answer a database question using the Graphoria MCP tools. Injects the user's question plus a workflow reminder (list_entities → describe_entity → graphql_execute) and the aggregate-syntax rules.",
|
|
397
|
+
argsSchema: z.object({
|
|
398
|
+
question: z.string().describe("Natural-language question about the database."),
|
|
399
|
+
}),
|
|
400
|
+
},
|
|
401
|
+
({ question }) => ({
|
|
402
|
+
messages: [
|
|
403
|
+
{
|
|
404
|
+
role: "user" as const,
|
|
405
|
+
content: {
|
|
406
|
+
type: "text" as const,
|
|
407
|
+
text: `Database-query request from the user:
|
|
408
|
+
|
|
409
|
+
> ${question}
|
|
410
|
+
|
|
411
|
+
Use the Graphoria MCP tools to answer. Required workflow:
|
|
412
|
+
|
|
413
|
+
1. list_entities — REQUIRES \`kind\` or \`search\`. Search matches resolverName AND tableDescription, so try natural-language keywords even when DB names are cryptic.
|
|
414
|
+
2. describe_entity — read the table's columns, the aggregateField signature, AND \`examples.list / examples.filter / examples.aggregate\` (these are pre-built queries using this table's real column names; prefer copying them over composing from scratch).
|
|
415
|
+
3. graphql_validate (optional) — confirm a hand-written query parses before executing.
|
|
416
|
+
4. graphql_execute — run the query.
|
|
417
|
+
|
|
418
|
+
For counts, totals, aggregates, grouping, breakdowns, or summaries: ALWAYS use \`<entity>_aggregate\` with \`groupBy\`. NEVER fetch all rows with the list field and count client-side. NEVER use Hasura-style \`{ aggregate { count } }\` nesting — that field does not exist.
|
|
419
|
+
|
|
420
|
+
Aggregate shape (\`key\` is an object, must be sub-selected):
|
|
421
|
+
|
|
422
|
+
query {
|
|
423
|
+
<entity>_aggregate(groupBy: [<col>]) {
|
|
424
|
+
key { <col> }
|
|
425
|
+
count
|
|
426
|
+
items { <fields> }
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
For a grand total: groupBy the primary key (or any non-null column) and sum the per-group \`count\` values client-side.
|
|
431
|
+
|
|
432
|
+
Present grouped results as a Markdown table with the grouped-by column(s) and the count.`,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
server.server.onerror = (err: unknown) => {
|
|
440
|
+
logger("mcp").error({ err }, "server error");
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
return server;
|
|
444
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { timingSafeEqual } from "crypto";
|
|
2
|
+
|
|
3
|
+
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/server";
|
|
4
|
+
|
|
5
|
+
import type { AnalyzedConfiguration } from "../../configuration";
|
|
6
|
+
import type { CreateMcpServerOptions } from "./create-server";
|
|
7
|
+
|
|
8
|
+
import { createMcpServer } from "./create-server";
|
|
9
|
+
import { logger } from "../../logging";
|
|
10
|
+
|
|
11
|
+
const safeCompare = (a: string, b: string): boolean => {
|
|
12
|
+
const bufA = Buffer.from(a);
|
|
13
|
+
const bufB = Buffer.from(b);
|
|
14
|
+
if (bufA.length !== bufB.length) return false;
|
|
15
|
+
return timingSafeEqual(bufA, bufB);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type CreateMCPRoutesOptions = CreateMcpServerOptions & {
|
|
19
|
+
requireAdminSecret?: boolean;
|
|
20
|
+
adminSecret?: string;
|
|
21
|
+
adminSecretHeader?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const jsonRpcError = (status: number, code: number, message: string) =>
|
|
25
|
+
new Response(
|
|
26
|
+
JSON.stringify({
|
|
27
|
+
jsonrpc: "2.0",
|
|
28
|
+
error: { code, message },
|
|
29
|
+
id: null,
|
|
30
|
+
}),
|
|
31
|
+
{
|
|
32
|
+
status,
|
|
33
|
+
headers: { "Content-Type": "application/json" },
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const handleMcpPost =
|
|
38
|
+
(analyzedConfiguration: AnalyzedConfiguration, options: CreateMCPRoutesOptions) =>
|
|
39
|
+
async (req: Request) => {
|
|
40
|
+
if (options.requireAdminSecret) {
|
|
41
|
+
const headerName = options.adminSecretHeader ?? "x-admin-secret";
|
|
42
|
+
const provided = req.headers.get(headerName);
|
|
43
|
+
const expected = options.adminSecret ?? "";
|
|
44
|
+
if (!provided || !expected || !safeCompare(provided, expected)) {
|
|
45
|
+
return jsonRpcError(401, -32001, "Unauthorized: admin secret required");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const server = createMcpServer(analyzedConfiguration, options);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
53
|
+
sessionIdGenerator: undefined,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
transport.onerror = (err: unknown) => {
|
|
57
|
+
logger("mcp").error({ err }, "transport error");
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
await server.connect(transport);
|
|
61
|
+
|
|
62
|
+
return await transport.handleRequest(req);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
logger("mcp").error({ err: e }, "MCP handler failed");
|
|
65
|
+
return jsonRpcError(500, -32603, "Internal server error");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const handleMcpGet = async (_req: Request) => jsonRpcError(405, -32000, "Method not allowed.");
|
|
70
|
+
|
|
71
|
+
const handleMcpDelete = async (_req: Request) => jsonRpcError(405, -32000, "Method not allowed.");
|
|
72
|
+
|
|
73
|
+
export const createMCPRoutes = (
|
|
74
|
+
analyzedConfiguration: AnalyzedConfiguration,
|
|
75
|
+
options: CreateMCPRoutesOptions = {},
|
|
76
|
+
) => ({
|
|
77
|
+
POST: handleMcpPost(analyzedConfiguration, options),
|
|
78
|
+
GET: handleMcpGet,
|
|
79
|
+
DELETE: handleMcpDelete,
|
|
80
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const GRAPHORIA_MCP_INSTRUCTIONS = `Graphoria MCP server. Anonymous-role-only GraphQL+REST APIs auto-generated from a database schema. Mutations and subscriptions are rejected by graphql_execute.
|
|
2
|
+
|
|
3
|
+
Discovery workflow:
|
|
4
|
+
1. list_entities (REQUIRES kind or search — see below; never call with no args)
|
|
5
|
+
2. describe_entity (columns, relationships, root-field signature, and ready-to-run example queries built from this table's real column names)
|
|
6
|
+
3. graphql_validate (optional — confirm a query parses against the schema)
|
|
7
|
+
4. graphql_execute (run the query)
|
|
8
|
+
For the full picture use resources: graphql://schema (SDL) and graphql://introspection (JSON).
|
|
9
|
+
|
|
10
|
+
## list_entities — always filter
|
|
11
|
+
Calls with no arguments are rejected. Pass at least one:
|
|
12
|
+
• kind: "table" | "operation" | "remote_schema" | "remote_rest" | "stored_procedure" | "queue_publisher" — browse a category
|
|
13
|
+
• search: "<substring>" — find by name fragment
|
|
14
|
+
Combine them to narrow further (e.g. kind: "table", search: "user").
|
|
15
|
+
|
|
16
|
+
# RULES — follow these strictly
|
|
17
|
+
|
|
18
|
+
## Aggregation requests
|
|
19
|
+
When the user asks for counts, aggregates, totals, grouping, breakdowns, or summaries:
|
|
20
|
+
→ ALWAYS use <entity>_aggregate with groupBy.
|
|
21
|
+
→ NEVER fetch all rows with the list field and count client-side.
|
|
22
|
+
→ NEVER use Hasura-style aggregate { count } nesting — it does not exist here.
|
|
23
|
+
See the Aggregates section below for the exact signature.
|
|
24
|
+
|
|
25
|
+
## Result presentation
|
|
26
|
+
When the user asks to "aggregate by X" or "group by X", present results as a table with the grouped-by column(s) and the count. Sum per-group counts for the total.
|
|
27
|
+
|
|
28
|
+
# GraphQL idioms — read before guessing
|
|
29
|
+
|
|
30
|
+
## Aggregates — Graphoria is NOT Hasura
|
|
31
|
+
|
|
32
|
+
### CRITICAL: key is an object — you MUST sub-select on it. Forgetting this is the #1 mistake.
|
|
33
|
+
|
|
34
|
+
Every <entity>_aggregate returns [<Entity>GroupBy!]!. Each GroupBy element has exactly:
|
|
35
|
+
key: <Entity> ← OBJECT TYPE — REQUIRES { } sub-selection
|
|
36
|
+
count: Int ← scalar
|
|
37
|
+
min: <Entity>Min ← only when numeric columns exist (same for max/sum/avg)
|
|
38
|
+
max: <Entity>Max
|
|
39
|
+
sum: <Entity>Sum
|
|
40
|
+
avg: <Entity>Avg
|
|
41
|
+
items: [<Entity>] ← raw rows in the bucket
|
|
42
|
+
|
|
43
|
+
groupBy: [<Entity>GroupByKeys]! is REQUIRED on every aggregate call (the list itself is mandatory).
|
|
44
|
+
|
|
45
|
+
### NEVER do this:
|
|
46
|
+
# MISSING groupBy (it's required):
|
|
47
|
+
users_aggregate { aggregate { count } }
|
|
48
|
+
|
|
49
|
+
# Missing { } around key sub-fields — 'key' is an object, not a scalar:
|
|
50
|
+
users_aggregate(groupBy: [role]) { key count }
|
|
51
|
+
|
|
52
|
+
# Trying to select the grouped-by column directly on GroupBy — it lives under key:
|
|
53
|
+
users_aggregate(groupBy: [role]) { role count }
|
|
54
|
+
|
|
55
|
+
# Trying to auto-generate groupBy enum values by UPPERCASING — the enum is lowercase:
|
|
56
|
+
users_aggregate(groupBy: [ROLE]) { key { role } count }
|
|
57
|
+
|
|
58
|
+
### ALWAYS do this:
|
|
59
|
+
# Minimum correct aggregate query (grouped-by columns under key { ... }):
|
|
60
|
+
query {
|
|
61
|
+
users_aggregate(groupBy: [role]) {
|
|
62
|
+
key { role }
|
|
63
|
+
count
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Full example with items and numeric aggregates:
|
|
68
|
+
query {
|
|
69
|
+
users_aggregate(groupBy: [role]) {
|
|
70
|
+
key { role }
|
|
71
|
+
count
|
|
72
|
+
items { id email }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
### Single grand-total count
|
|
77
|
+
groupBy is still required. Group by the primary key (unique per row), then sum counts client-side:
|
|
78
|
+
query {
|
|
79
|
+
users_aggregate(groupBy: [id]) {
|
|
80
|
+
count
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
Then sum the count values across all returned groups.
|
|
84
|
+
|
|
85
|
+
## where — operator set depends on the column's GraphQL type
|
|
86
|
+
Shape: where: { <col>: { <op>: value }, <relationship>: { … nested where … }, … }. Relationship and reverse-relationship names from the entity type are also valid keys for nested filtering.
|
|
87
|
+
|
|
88
|
+
IntCondition / FloatCondition: eq, neq, gt, gte, lt, lte, in, between, is_null, not_null
|
|
89
|
+
StringCondition: eq, neq, like, in, is_null, not_null # no gt/lt/between
|
|
90
|
+
BooleanCondition: eq, neq, is_null, not_null # no comparison ops
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
where: { age: { gte: 18 }, role: { in: ["student","guest"] }, deleted_at: { is_null: true } }
|
|
94
|
+
|
|
95
|
+
## orderBy
|
|
96
|
+
Shape: orderBy: [{ <col>: <OrderByEnum> }]. OrderByEnum values: ASC, DESC, ASC_NULLS_FIRST, ASC_NULLS_LAST, DESC_NULLS_FIRST, DESC_NULLS_LAST.
|
|
97
|
+
|
|
98
|
+
## Pagination
|
|
99
|
+
limit: Int, offset: Int on both list and aggregate fields.
|
|
100
|
+
|
|
101
|
+
## Mutations / subscriptions
|
|
102
|
+
Rejected at the MCP boundary. Use REST (rest_execute) for state changes if an operation is exposed there.
|
|
103
|
+
`;
|