Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query distinct dependencies #1398

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/limit.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/plugins/PgBlockHeightPlugin.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions packages/query/src/graphql/plugins/PgDistinctPlugin.ts
Original file line number Diff line number Diff line change
@@ -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 = <T1, T2>(base: T1, extra: T2, hint?: string) => T1 & T2;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/plugins/PgSubscriptionPlugin.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
48 changes: 24 additions & 24 deletions packages/query/src/graphql/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/graphql/plugins/smartTagsPlugin.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
85 changes: 81 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3891,15 +3893,13 @@ __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
lodash: ^4.17.21
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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down