diff --git a/packages/query/package.json b/packages/query/package.json index 2a947f425b..626cfa863d 100644 --- a/packages/query/package.json +++ b/packages/query/package.json @@ -38,17 +38,17 @@ "@nestjs/platform-express": "^8.2.6", "@subql/common": "workspace:*", "@subql/utils": "workspace:*", + "@subql/x-graphile-build-pg": "^4.12.3-0.1.0", + "@subql/x-postgraphile-core": "^4.12.3-0.1.0", "apollo-server-express": "^3.6.2", "express-pino-logger": "^6.0.0", "graphile-build": "^4.12.2", - "graphile-build-pg": "^4.12.2", "graphile-utils": "^4.12.2", "graphql": "^15.8.0", "graphql-query-complexity": "^0.11.0", "lodash": "^4.17.21", "pg": "^8.7.1", "postgraphile": "^4.12.9", - "postgraphile-core": "^4.12.2", "postgraphile-plugin-connection-filter": "^2.2.2", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", diff --git a/packages/query/src/graphql/graphql.module.ts b/packages/query/src/graphql/graphql.module.ts index 4573775853..c90911989a 100644 --- a/packages/query/src/graphql/graphql.module.ts +++ b/packages/query/src/graphql/graphql.module.ts @@ -5,6 +5,7 @@ import PgPubSub from '@graphile/pg-pubsub'; import {Module, OnModuleDestroy, OnModuleInit} from '@nestjs/common'; import {HttpAdapterHost} from '@nestjs/core'; import {delay} from '@subql/common'; +import {getPostGraphileBuilder, PostGraphileCoreOptions} from '@subql/x-postgraphile-core'; import { ApolloServerPluginCacheControl, ApolloServerPluginLandingPageDisabled, @@ -16,7 +17,6 @@ import {execute, GraphQLSchema, subscribe} from 'graphql'; import {set} from 'lodash'; import {Pool} from 'pg'; import {makePluginHook} from 'postgraphile'; -import {getPostGraphileBuilder, PostGraphileCoreOptions} from 'postgraphile-core'; import {SubscriptionServer} from 'subscriptions-transport-ws'; import {Config} from '../configure'; import {getLogger, PinoConfig} from '../utils/logger'; diff --git a/packages/query/src/graphql/graphql.test.ts b/packages/query/src/graphql/graphql.test.ts index f36e97b951..ef4ca8b48c 100644 --- a/packages/query/src/graphql/graphql.test.ts +++ b/packages/query/src/graphql/graphql.test.ts @@ -1,9 +1,9 @@ // Copyright 2020-2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 +import {getPostGraphileBuilder} from '@subql/x-postgraphile-core'; import {ApolloServer, gql} from 'apollo-server-express'; import {Pool} from 'pg'; -import {getPostGraphileBuilder} from 'postgraphile-core'; import {Config} from '../configure'; import {getYargsOption} from '../yargs'; import {plugins} from './plugins'; diff --git a/packages/query/src/graphql/limit.test.ts b/packages/query/src/graphql/limit.test.ts index 11403d869e..dba3cece5e 100644 --- a/packages/query/src/graphql/limit.test.ts +++ b/packages/query/src/graphql/limit.test.ts @@ -1,9 +1,9 @@ // Copyright 2020-2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 +import {getPostGraphileBuilder} from '@subql/x-postgraphile-core'; import {ApolloServer, gql} from 'apollo-server-express'; import {Pool} from 'pg'; -import {getPostGraphileBuilder} from 'postgraphile-core'; import {Config} from '../configure'; import {getYargsOption} from '../yargs'; import {plugins} from './plugins'; diff --git a/packages/query/src/graphql/plugins/PgBackwardRelationPlugin.ts b/packages/query/src/graphql/plugins/PgBackwardRelationPlugin.ts index 39fb285e96..dc499c68ee 100644 --- a/packages/query/src/graphql/plugins/PgBackwardRelationPlugin.ts +++ b/packages/query/src/graphql/plugins/PgBackwardRelationPlugin.ts @@ -6,7 +6,7 @@ import debugFactory from 'debug'; -const debug = debugFactory('graphile-build-pg'); +const debug = debugFactory('@subql/x-graphile-build-pg'); const OMIT = 0; const DEPRECATED = 1; diff --git a/packages/query/src/graphql/plugins/PgBlockHeightPlugin.ts b/packages/query/src/graphql/plugins/PgBlockHeightPlugin.ts index c5dd695612..b01306ba99 100644 --- a/packages/query/src/graphql/plugins/PgBlockHeightPlugin.ts +++ b/packages/query/src/graphql/plugins/PgBlockHeightPlugin.ts @@ -1,8 +1,8 @@ // Copyright 2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 +import {QueryBuilder} from '@subql/x-graphile-build-pg'; import {Plugin} from 'graphile-build'; -import {QueryBuilder} from 'graphile-build-pg'; import {GraphQLString} from 'graphql'; export const PgBlockHeightPlugin: Plugin = (builder) => { diff --git a/packages/query/src/graphql/plugins/PgConnectionArgFirstLastBeforeAfter.ts b/packages/query/src/graphql/plugins/PgConnectionArgFirstLastBeforeAfter.ts index dbdf0ed468..cf8fb750ab 100644 --- a/packages/query/src/graphql/plugins/PgConnectionArgFirstLastBeforeAfter.ts +++ b/packages/query/src/graphql/plugins/PgConnectionArgFirstLastBeforeAfter.ts @@ -4,7 +4,7 @@ // overwrite the official plugin: https://github.com/graphile/graphile-engine/blob/v4/packages/graphile-build-pg/src/plugins/PgConnectionArgFirstLastBeforeAfter.js // to support max record rewrite, which to prevent the db performance issue. -import {QueryBuilder} from 'graphile-build-pg'; +import {QueryBuilder} from '@subql/x-graphile-build-pg'; import {argv} from '../../yargs'; const MAX_ENTITY_COUNT = 100; diff --git a/packages/query/src/graphql/plugins/PgDistinctPlugin.ts b/packages/query/src/graphql/plugins/PgDistinctPlugin.ts index 2311b1d28c..ddd2baeb60 100644 --- a/packages/query/src/graphql/plugins/PgDistinctPlugin.ts +++ b/packages/query/src/graphql/plugins/PgDistinctPlugin.ts @@ -1,10 +1,11 @@ // Copyright 2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 +import {PgClass, QueryBuilder} from '@subql/x-graphile-build-pg'; import {Build, Plugin} from 'graphile-build'; -import {PgClass, QueryBuilder} from 'graphile-build-pg'; import type {GraphQLEnumType} from 'graphql'; import * as PgSql from 'pg-sql2'; +import {SQLNode} from 'pg-sql2'; type Extend = (base: T1, extra: T2, hint?: string) => T1 & T2; @@ -82,8 +83,8 @@ export const PgDistinctPlugin: Plugin = (builder) => { return; } - - const id = sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(fieldName)}`; + //export declare type SQL = SQLNode | SQLQuery; + const id = sql.fragment`${queryBuilder.getTableAlias() as unknown as SQLNode}.${sql.identifier(fieldName)}`; // Dependent on https://github.com/graphile/graphile-engine/pull/805 (queryBuilder as any).distinctOn(id); diff --git a/packages/query/src/graphql/plugins/PgOrderByAggregatesPlugin.ts b/packages/query/src/graphql/plugins/PgOrderByAggregatesPlugin.ts index 60549aa458..ea1b9921a4 100644 --- a/packages/query/src/graphql/plugins/PgOrderByAggregatesPlugin.ts +++ b/packages/query/src/graphql/plugins/PgOrderByAggregatesPlugin.ts @@ -7,8 +7,8 @@ */ import {AggregateSpec} from '@graphile/pg-aggregates/dist/interfaces'; +import type {SQL, QueryBuilder, PgClass, PgEntity} from '@subql/x-graphile-build-pg'; import type {Plugin} from 'graphile-build'; -import type {SQL, QueryBuilder, PgClass, PgEntity} from 'graphile-build-pg'; type OrderBySpecIdentity = string | SQL | ((options: {queryBuilder: QueryBuilder}) => SQL); diff --git a/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts b/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts index f9533b7834..0f245da430 100644 --- a/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts +++ b/packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts @@ -1,7 +1,7 @@ // Copyright 2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 -import {PgIntrospectionResultsByKind} from 'graphile-build-pg'; +import {PgIntrospectionResultsByKind} from '@subql/x-graphile-build-pg'; import {makeExtendSchemaPlugin, gql, embed} from 'graphile-utils'; const filter = (event, args) => { diff --git a/packages/query/src/graphql/plugins/index.ts b/packages/query/src/graphql/plugins/index.ts index 56c48ea846..438ec85ff9 100644 --- a/packages/query/src/graphql/plugins/index.ts +++ b/packages/query/src/graphql/plugins/index.ts @@ -14,30 +14,30 @@ import { AddQueriesToSubscriptionsPlugin, TrimEmptyDescriptionsPlugin, } from 'graphile-build/node8plus/plugins'; -import PgBasicsPlugin from 'graphile-build-pg/node8plus/plugins/PgBasicsPlugin'; -import PgIntrospectionPlugin from 'graphile-build-pg/node8plus/plugins/PgIntrospectionPlugin'; -import PgTypesPlugin from 'graphile-build-pg/node8plus/plugins/PgTypesPlugin'; -import PgTablesPlugin from 'graphile-build-pg/node8plus/plugins/PgTablesPlugin'; -import PgConnectionArgOrderBy from 'graphile-build-pg/node8plus/plugins/PgConnectionArgOrderBy'; -import PgConnectionArgOrderByDefaultValue from 'graphile-build-pg/node8plus/plugins/PgConnectionArgOrderByDefaultValue'; -import PgConditionComputedColumnPlugin from 'graphile-build-pg/node8plus/plugins/PgConditionComputedColumnPlugin'; -import PgAllRows from 'graphile-build-pg/node8plus/plugins/PgAllRows'; -import PgColumnsPlugin from 'graphile-build-pg/node8plus/plugins/PgColumnsPlugin'; -import PgColumnDeprecationPlugin from 'graphile-build-pg/node8plus/plugins/PgColumnDeprecationPlugin'; -import PgForwardRelationPlugin from 'graphile-build-pg/node8plus/plugins/PgForwardRelationPlugin'; -import PgRowByUniqueConstraint from 'graphile-build-pg/node8plus/plugins/PgRowByUniqueConstraint'; -import PgComputedColumnsPlugin from 'graphile-build-pg/node8plus/plugins/PgComputedColumnsPlugin'; -import PgQueryProceduresPlugin from 'graphile-build-pg/node8plus/plugins/PgQueryProceduresPlugin'; -import PgOrderAllColumnsPlugin from 'graphile-build-pg/node8plus/plugins/PgOrderAllColumnsPlugin'; -import PgOrderComputedColumnsPlugin from 'graphile-build-pg/node8plus/plugins/PgOrderComputedColumnsPlugin'; -import PgOrderByPrimaryKeyPlugin from 'graphile-build-pg/node8plus/plugins/PgOrderByPrimaryKeyPlugin'; -import PgRowNode from 'graphile-build-pg/node8plus/plugins/PgRowNode'; -import PgNodeAliasPostGraphile from 'graphile-build-pg/node8plus/plugins/PgNodeAliasPostGraphile'; -import PgRecordReturnTypesPlugin from 'graphile-build-pg/node8plus/plugins/PgRecordReturnTypesPlugin'; -import PgRecordFunctionConnectionPlugin from 'graphile-build-pg/node8plus/plugins/PgRecordFunctionConnectionPlugin'; -import PgScalarFunctionConnectionPlugin from 'graphile-build-pg/node8plus/plugins/PgScalarFunctionConnectionPlugin'; -import PageInfoStartEndCursor from 'graphile-build-pg/node8plus/plugins/PageInfoStartEndCursor'; -import PgConnectionTotalCount from 'graphile-build-pg/node8plus/plugins/PgConnectionTotalCount'; +import PgBasicsPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgBasicsPlugin'; +import PgIntrospectionPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgIntrospectionPlugin'; +import PgTypesPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgTypesPlugin'; +import PgTablesPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgTablesPlugin'; +import PgConnectionArgOrderBy from '@subql/x-graphile-build-pg/node8plus/plugins/PgConnectionArgOrderBy'; +import PgConnectionArgOrderByDefaultValue from '@subql/x-graphile-build-pg/node8plus/plugins/PgConnectionArgOrderByDefaultValue'; +import PgConditionComputedColumnPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgConditionComputedColumnPlugin'; +import PgAllRows from '@subql/x-graphile-build-pg/node8plus/plugins/PgAllRows'; +import PgColumnsPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgColumnsPlugin'; +import PgColumnDeprecationPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgColumnDeprecationPlugin'; +import PgForwardRelationPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgForwardRelationPlugin'; +import PgRowByUniqueConstraint from '@subql/x-graphile-build-pg/node8plus/plugins/PgRowByUniqueConstraint'; +import PgComputedColumnsPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgComputedColumnsPlugin'; +import PgQueryProceduresPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgQueryProceduresPlugin'; +import PgOrderAllColumnsPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgOrderAllColumnsPlugin'; +import PgOrderComputedColumnsPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgOrderComputedColumnsPlugin'; +import PgOrderByPrimaryKeyPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgOrderByPrimaryKeyPlugin'; +import PgRowNode from '@subql/x-graphile-build-pg/node8plus/plugins/PgRowNode'; +import PgNodeAliasPostGraphile from '@subql/x-graphile-build-pg/node8plus/plugins/PgNodeAliasPostGraphile'; +import PgRecordReturnTypesPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgRecordReturnTypesPlugin'; +import PgRecordFunctionConnectionPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgRecordFunctionConnectionPlugin'; +import PgScalarFunctionConnectionPlugin from '@subql/x-graphile-build-pg/node8plus/plugins/PgScalarFunctionConnectionPlugin'; +import PageInfoStartEndCursor from '@subql/x-graphile-build-pg/node8plus/plugins/PageInfoStartEndCursor'; +import PgConnectionTotalCount from '@subql/x-graphile-build-pg/node8plus/plugins/PgConnectionTotalCount'; import PgSimplifyInflectorPlugin from '@graphile-contrib/pg-simplify-inflector'; import PgManyToManyPlugin from '@graphile-contrib/pg-many-to-many'; diff --git a/packages/query/src/graphql/plugins/smartTagsPlugin.ts b/packages/query/src/graphql/plugins/smartTagsPlugin.ts index 9f38ca9835..4a7766cf5d 100644 --- a/packages/query/src/graphql/plugins/smartTagsPlugin.ts +++ b/packages/query/src/graphql/plugins/smartTagsPlugin.ts @@ -1,7 +1,7 @@ // Copyright 2020-2022 OnFinality Limited authors & contributors // SPDX-License-Identifier: Apache-2.0 -import {PgEntity, PgEntityKind} from 'graphile-build-pg'; +import {PgEntity, PgEntityKind} from '@subql/x-graphile-build-pg'; import {makePgSmartTagsPlugin} from 'graphile-utils'; export const smartTagsPlugin = makePgSmartTagsPlugin([ diff --git a/yarn.lock b/yarn.lock index 6dbac82144..5476da81a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3882,6 +3882,8 @@ __metadata: "@nestjs/testing": ^8.2.6 "@subql/common": "workspace:*" "@subql/utils": "workspace:*" + "@subql/x-graphile-build-pg": ^4.12.3-0.1.0 + "@subql/x-postgraphile-core": ^4.12.3-0.1.0 "@types/express": ^4.17.13 "@types/express-pino-logger": ^4.0.3 "@types/jest": ^27.4.0 @@ -3891,7 +3893,6 @@ __metadata: apollo-server-express: ^3.6.2 express-pino-logger: ^6.0.0 graphile-build: ^4.12.2 - graphile-build-pg: ^4.12.2 graphile-utils: ^4.12.2 graphql: ^15.8.0 graphql-query-complexity: ^0.11.0 @@ -3899,7 +3900,6 @@ __metadata: nodemon: ^2.0.15 pg: ^8.7.1 postgraphile: ^4.12.9 - postgraphile-core: ^4.12.2 postgraphile-plugin-connection-filter: ^2.2.2 reflect-metadata: ^0.1.13 rimraf: ^3.0.2 @@ -4012,6 +4012,24 @@ __metadata: languageName: unknown linkType: soft +"@subql/x-graphile-build-pg@npm:4.12.3-0.1.0, @subql/x-graphile-build-pg@npm:^4.12.3-0.1.0": + version: 4.12.3-0.1.0 + resolution: "@subql/x-graphile-build-pg@npm:4.12.3-0.1.0" + dependencies: + "@graphile/lru": 4.11.0 + chalk: ^2.4.2 + debug: ^4.1.1 + graphile-build: 4.12.3 + jsonwebtoken: ^8.5.1 + lodash: ">=4 <5" + lru-cache: ">=4 <5" + pg-sql2: 4.12.3 + peerDependencies: + pg: ">=6.1.0 <9" + checksum: a2f6632b3fbb0e3930932069fca1dc0c8f390df8c20472b1b20f13fb588d801077ed46c19188de90db99ae0349a62244c4d974e8303006c50fda59ca7aa98fc1 + languageName: node + linkType: hard + "@subql/x-merkle-mountain-range@npm:2.0.0-0.1.2, @subql/x-merkle-mountain-range@npm:^2.0.0-0.1.2": version: 2.0.0-0.1.2 resolution: "@subql/x-merkle-mountain-range@npm:2.0.0-0.1.2" @@ -4027,6 +4045,20 @@ __metadata: languageName: node linkType: hard +"@subql/x-postgraphile-core@npm:^4.12.3-0.1.0": + version: 4.12.3-0.1.0 + resolution: "@subql/x-postgraphile-core@npm:4.12.3-0.1.0" + dependencies: + "@subql/x-graphile-build-pg": 4.12.3-0.1.0 + graphile-build: 4.12.3 + tslib: ^2.0.1 + peerDependencies: + graphql: ">=0.9 <0.14 || ^14.0.2 || ^15.4.0" + pg: ">=6.1.0 <9" + checksum: 70fb38ad502931e732c7fea3ef10e3bbf770f3d8efb8e393a11b2250803644ac6dd2ed19870135b5459c19fea64fe7db3ab53173854d26af5d4f3b7d4068da42 + languageName: node + linkType: hard + "@substrate/connect-extension-protocol@npm:^1.0.1": version: 1.0.1 resolution: "@substrate/connect-extension-protocol@npm:1.0.1" @@ -9436,7 +9468,7 @@ __metadata: languageName: node linkType: hard -"graphile-build-pg@npm:4.12.2, graphile-build-pg@npm:^4.12.2": +"graphile-build-pg@npm:4.12.2": version: 4.12.2 resolution: "graphile-build-pg@npm:4.12.2" dependencies: @@ -9473,6 +9505,25 @@ __metadata: languageName: node linkType: hard +"graphile-build@npm:4.12.3": + version: 4.12.3 + resolution: "graphile-build@npm:4.12.3" + dependencies: + "@graphile/lru": 4.11.0 + chalk: ^2.4.2 + debug: ^4.1.1 + graphql-parse-resolve-info: 4.12.3 + iterall: ^1.2.2 + lodash: ">=4 <5" + lru-cache: ^5.0.0 + pluralize: ^7.0.0 + semver: ^6.0.0 + peerDependencies: + graphql: ">=0.9 <0.14 || ^14.0.2 || ^15.4.0" + checksum: ceea109a75cf928c5dd5bc7164117d33e6540106bdb4049d4d53b98430c90b11162b365a93ff7e6770cc630ecbd041af3fe807cea9710c9921c1fcc9f7fd322e + languageName: node + linkType: hard + "graphile-utils@npm:^4.12.0-alpha.0, graphile-utils@npm:^4.12.2": version: 4.12.2 resolution: "graphile-utils@npm:4.12.2" @@ -9499,6 +9550,18 @@ __metadata: languageName: node linkType: hard +"graphql-parse-resolve-info@npm:4.12.3": + version: 4.12.3 + resolution: "graphql-parse-resolve-info@npm:4.12.3" + dependencies: + debug: ^4.1.1 + tslib: ^2.0.1 + peerDependencies: + graphql: ">=0.9 <0.14 || ^14.0.2 || ^15.4.0" + checksum: 01b0517487631d5b1c50f75fbb194d6e2fe731042eaf62ff1ba5b32f71964bc204dbf365fec9dfb1b387ad008786158f2469a868e8591a59b75cb96a645d1bdb + languageName: node + linkType: hard + "graphql-query-complexity@npm:^0.11.0": version: 0.11.0 resolution: "graphql-query-complexity@npm:0.11.0" @@ -13677,6 +13740,20 @@ __metadata: languageName: node linkType: hard +"pg-sql2@npm:4.12.3": + version: 4.12.3 + resolution: "pg-sql2@npm:4.12.3" + dependencies: + "@graphile/lru": 4.11.0 + "@types/pg": ">=6 <9" + debug: ">=3 <5" + tslib: ^2.0.1 + peerDependencies: + pg: ">=6.1.0 <9" + checksum: 3b7644b38138b24d204153e053f4ee798c30a75b8bec89bcdad835eb32aa0f0e3f6cbed84f2d934e08f3fb8e8589a7e3f5a78a0a468d3d8678cababe77b1f299 + languageName: node + linkType: hard + "pg-types@npm:^2.1.0, pg-types@npm:^2.2.0": version: 2.2.0 resolution: "pg-types@npm:2.2.0" @@ -13828,7 +13905,7 @@ __metadata: languageName: node linkType: hard -"postgraphile-core@npm:4.12.2, postgraphile-core@npm:^4.12.2": +"postgraphile-core@npm:4.12.2": version: 4.12.2 resolution: "postgraphile-core@npm:4.12.2" dependencies: