Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/loud-hornets-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphprotocol/client-auto-pagination': patch
'@graphprotocol/client-block-tracking': patch
---

Respect the changes done by other transforms
3 changes: 3 additions & 0 deletions examples/transforms/.graphclientrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions packages/auto-pagination/__tests__/auto-pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` }))
Expand Down Expand Up @@ -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<any> = await execute({
schema: wrappedSchema,
document: parse(query),
})
expect(result.data?.my_users).toHaveLength(15000)
expect(result.data?.my_users).toEqual(users.slice(0, 15000))
})
})
3 changes: 2 additions & 1 deletion packages/auto-pagination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 8 additions & 10 deletions packages/auto-pagination/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,12 @@ export default class AutoPaginationTransform implements MeshTransform {
}
}

transformSchema(
schema: GraphQLSchema,
subschemaConfig: SubschemaConfig<any, any, any, any>,
transformedSchema: GraphQLSchema | undefined,
) {
transformSchema(schema: GraphQLSchema, subschemaConfig: SubschemaConfig<any, any, any, any>) {
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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/block-tracking/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -175,9 +175,9 @@ export default class BlockTrackingTransform implements MeshTransform {
}
}

transformSchema(schema: GraphQLSchema) {
transformSchema(schema: GraphQLSchema, subschemaConfig: SubschemaConfig<any, any, any, any>): GraphQLSchema {
if (this.config.validateSchema) {
validateSchema(schema, this.config)
validateSchema(subschemaConfig.schema, this.config)
}
return schema
}
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down