diff --git a/.changeset/loud-hornets-leave.md b/.changeset/loud-hornets-leave.md new file mode 100644 index 00000000..3f64ac10 --- /dev/null +++ b/.changeset/loud-hornets-leave.md @@ -0,0 +1,6 @@ +--- +'@graphprotocol/client-auto-pagination': patch +'@graphprotocol/client-block-tracking': patch +--- + +Respect the changes done by other transforms diff --git a/examples/transforms/.graphclientrc.yml b/examples/transforms/.graphclientrc.yml index a7375413..889c4443 100644 --- a/examples/transforms/.graphclientrc.yml +++ b/examples/transforms/.graphclientrc.yml @@ -4,6 +4,9 @@ sources: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 transforms: + - prefix: + value: uni_ + includeRootOperations: true # Enable Automatic Block Tracking - blockTracking: validateSchema: true diff --git a/packages/auto-pagination/__tests__/auto-pagination.test.ts b/packages/auto-pagination/__tests__/auto-pagination.test.ts index c4a65d22..2891667d 100644 --- a/packages/auto-pagination/__tests__/auto-pagination.test.ts +++ b/packages/auto-pagination/__tests__/auto-pagination.test.ts @@ -2,6 +2,9 @@ import { makeExecutableSchema } from '@graphql-tools/schema' import { wrapSchema } from '@graphql-tools/wrap' import { execute, ExecutionResult, parse } from 'graphql' import AutoPaginationTransform from '../src' +import PrefixTransform from '@graphql-mesh/transform-prefix' +import LocalforageCache from '@graphql-mesh/cache-localforage' +import { PubSub } from '@graphql-mesh/utils' describe('Auto Pagination', () => { const users = new Array(20000).fill({}).map((_, i) => ({ id: (i + 1).toString(), name: `User ${i + 1}` })) @@ -158,4 +161,37 @@ describe('Auto Pagination', () => { expect(result.data?.users).toHaveLength(15000) expect(result.data?.users).toEqual(users.slice(0, 15000)) }) + it('should work with prefix transform properly', async () => { + const wrappedSchema = wrapSchema({ + schema, + transforms: [ + new PrefixTransform({ + baseDir: process.cwd(), + cache: new LocalforageCache(), + pubsub: new PubSub(), + apiName: 'test', + config: { + value: 'my_', + includeRootOperations: true, + }, + importFn: (m) => import(m), + }), + new AutoPaginationTransform(), + ], + }) + const query = /* GraphQL */ ` + query { + my_users(first: 15000) { + id + name + } + } + ` + const result: ExecutionResult = await execute({ + schema: wrappedSchema, + document: parse(query), + }) + expect(result.data?.my_users).toHaveLength(15000) + expect(result.data?.my_users).toEqual(users.slice(0, 15000)) + }) }) diff --git a/packages/auto-pagination/package.json b/packages/auto-pagination/package.json index dc86830c..c0b90072 100644 --- a/packages/auto-pagination/package.json +++ b/packages/auto-pagination/package.json @@ -46,7 +46,8 @@ "tslib": "2.4.0" }, "devDependencies": { - "@types/lodash": "4.14.182" + "@types/lodash": "4.14.182", + "@graphql-mesh/transform-prefix": "0.11.47" }, "peerDependencies": { "graphql": "^15.2.0 || ^16.0.0", diff --git a/packages/auto-pagination/src/index.ts b/packages/auto-pagination/src/index.ts index 8dd92496..03421d58 100644 --- a/packages/auto-pagination/src/index.ts +++ b/packages/auto-pagination/src/index.ts @@ -78,16 +78,12 @@ export default class AutoPaginationTransform implements MeshTransform { } } - transformSchema( - schema: GraphQLSchema, - subschemaConfig: SubschemaConfig, - transformedSchema: GraphQLSchema | undefined, - ) { + transformSchema(schema: GraphQLSchema, subschemaConfig: SubschemaConfig) { if (this.config.validateSchema) { - validateSchema(schema, this.config) + validateSchema(subschemaConfig.schema, this.config) } - if (transformedSchema != null) { - const queryType = transformedSchema.getQueryType() + if (schema != null) { + const queryType = schema.getQueryType() if (queryType != null) { const queryFields = queryType.getFields() for (const fieldName in queryFields) { @@ -114,7 +110,8 @@ export default class AutoPaginationTransform implements MeshTransform { const askedRecords = Math.min(remainingRecords, this.config.skipArgumentLimit) _.set(newArgs, this.config.firstArgumentName, askedRecords) const result = await delegateToSchema({ - schema: transformedSchema, + schema, + fieldName, args: newArgs, context, info, @@ -244,7 +241,8 @@ export default class AutoPaginationTransform implements MeshTransform { const finalData = {} for (const fullAliasName in originalResult.data) { if (fullAliasName.startsWith('splitted_')) { - const [, , aliasName] = fullAliasName.split('_') + const [, , ...rest] = fullAliasName.split('_') + const aliasName = rest.join('_') finalData[aliasName] = finalData[aliasName] || [] for (const record of originalResult.data[fullAliasName]) { finalData[aliasName].push(record) diff --git a/packages/block-tracking/src/index.ts b/packages/block-tracking/src/index.ts index 839411f5..ecb39df0 100644 --- a/packages/block-tracking/src/index.ts +++ b/packages/block-tracking/src/index.ts @@ -1,5 +1,5 @@ import type { MeshTransform } from '@graphql-mesh/types' -import type { DelegationContext } from '@graphql-tools/delegate' +import type { DelegationContext, SubschemaConfig } from '@graphql-tools/delegate' import type { ExecutionRequest } from '@graphql-tools/utils' import { memoize1, memoize2 } from '@graphql-tools/utils' import { @@ -175,9 +175,9 @@ export default class BlockTrackingTransform implements MeshTransform { } } - transformSchema(schema: GraphQLSchema) { + transformSchema(schema: GraphQLSchema, subschemaConfig: SubschemaConfig): GraphQLSchema { if (this.config.validateSchema) { - validateSchema(schema, this.config) + validateSchema(subschemaConfig.schema, this.config) } return schema } diff --git a/yarn.lock b/yarn.lock index f8249e07..33063a9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1670,6 +1670,19 @@ graphql-scalars "1.17.0" tslib "^2.3.1" +"@graphql-mesh/transform-prefix@0.11.47": + version "0.11.47" + resolved "https://registry.yarnpkg.com/@graphql-mesh/transform-prefix/-/transform-prefix-0.11.47.tgz#48a797da4fe4c4cd629431b58e0bb1f135ba4a36" + integrity sha512-gVUkAr0w0wLL5jFPxdmMYSXWYq9b96//mdESF9vrksiP9lE7JOLNzI08OSSy0lU6TEFNmB/x7CymJ5axyAz7Pg== + dependencies: + "@graphql-mesh/types" "0.73.2" + "@graphql-mesh/utils" "0.35.2" + "@graphql-tools/delegate" "8.7.10" + "@graphql-tools/utils" "8.6.12" + "@graphql-tools/wrap" "8.4.19" + graphql-scalars "1.17.0" + tslib "^2.3.1" + "@graphql-mesh/transform-rename@0.12.46": version "0.12.46" resolved "https://registry.yarnpkg.com/@graphql-mesh/transform-rename/-/transform-rename-0.12.46.tgz#06fd775770bb7b84a7ff115f830d366735811133"