-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): fix memoization logic on batching (#4605)
* fix(runtime): fix memoization logic on batching * Fix * chore(dependencies): updated changesets for modified dependencies * Cleanup * Go Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a5db45a
commit 31a6471
Showing
49 changed files
with
493 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@graphql-mesh/graphql": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/url-loader/v/7.16.4) (from `7.16.2`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
5 changes: 5 additions & 0 deletions
5
.changeset/@graphql-mesh_merger-federation-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/merger-federation": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
7 changes: 7 additions & 0 deletions
7
.changeset/@graphql-mesh_merger-stitching-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@graphql-mesh/merger-stitching": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitch/v/8.7.13) (from `8.7.11`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitching-directives/v/2.3.11) (from `2.3.9`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/mysql": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/odata": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/postgraphile": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@graphql-mesh/runtime": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/batch-delegate/v/8.4.1) (from `8.3.9`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-encapsulate-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-encapsulate": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-federation-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-federation": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitching-directives/v/2.3.11) (from `2.3.9`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-filter-schema-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-filter-schema": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-hoist-field-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-hoist-field": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-naming-convention-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-naming-convention": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-prefix-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-prefix": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-rename-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-rename": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/wrap/v/9.2.3) (from `9.2.1`, in `dependencies`) |
6 changes: 6 additions & 0 deletions
6
.changeset/@graphql-mesh_transform-type-merging-4605-dependencies.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/transform-type-merging": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/stitching-directives/v/2.3.11) (from `2.3.9`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@graphql-mesh/types": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/batch-delegate/v/8.4.1) (from `8.3.9`, in `dependencies`) | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/utils": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-tools/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-tools/delegate/v/9.0.8) (from `9.0.6`, in `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-mesh/runtime': patch | ||
--- | ||
|
||
Fix memoization on batch delegation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
sources: | ||
- name: ExampleAPI | ||
handler: | ||
openapi: | ||
baseUrl: http://localhost:4001 | ||
source: ./example-api/openapi.json | ||
|
||
additionalTypeDefs: | | ||
extend type Query { | ||
user(id: Float!): User | ||
} | ||
additionalResolvers: | ||
- ./additional-resolvers.ts | ||
|
||
serve: | ||
browser: false | ||
|
||
documents: | ||
- ./example-query.graphql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { print } from 'graphql'; | ||
import { Resolvers } from './.mesh'; | ||
|
||
export const resolvers: Resolvers = { | ||
Query: { | ||
user(root, args, context, info) { | ||
return context.ExampleAPI.Mutation.usersByIds({ | ||
root, | ||
context, | ||
info, | ||
// Key for the following batched request | ||
key: args.id, | ||
// Arguments for the following batched request | ||
argsFromKeys: ids => ({ input: { ids } }), | ||
// Function to extract the result from the batched response | ||
valuesFromResults: data => data.results, | ||
// Function to generate the selectionSet for the batched request | ||
selectionSet: userSelectionSet => /* GraphQL */ ` | ||
{ | ||
results ${print(userSelectionSet)} # Will print something like { id name } | ||
} | ||
`, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Router } from 'itty-router'; | ||
import { createServerAdapter } from '@whatwg-node/server'; | ||
import { Response } from '@whatwg-node/fetch'; | ||
|
||
export function createApp() { | ||
const app = createServerAdapter(Router()); | ||
|
||
const users = [ | ||
{ id: 1, name: 'John Doe' }, | ||
{ id: 2, name: 'Jane Doe' }, | ||
{ id: 3, name: 'John Smith' }, | ||
{ id: 4, name: 'Jane Smith' }, | ||
]; | ||
|
||
app.post('/users_by_ids', async (req: Request) => { | ||
const body = await req.json(); | ||
const ids = body.ids; | ||
const results = users.filter(user => ids.includes(user.id)); | ||
return new Response( | ||
JSON.stringify({ | ||
results, | ||
}), | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
); | ||
}); | ||
|
||
return app; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createServer } from 'http'; | ||
import { createApp } from './app'; | ||
|
||
createServer(createApp()).listen(4001, () => { | ||
console.log('Listening on port 4001'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "API Name", | ||
"version": "1.0" | ||
}, | ||
"paths": { | ||
"/users_by_ids": { | ||
"post": { | ||
"operationId": "usersByIds", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"title": "UsersByIdRequest", | ||
"type": "object", | ||
"properties": { | ||
"ids": { | ||
"type": "array", | ||
"items": { | ||
"type": "number" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "Success", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/UsersByIdResponse" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"UsersByIdResponse": { | ||
"type": "object", | ||
"properties": { | ||
"results": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/User" | ||
} | ||
} | ||
} | ||
}, | ||
"User": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fragment UserF on User { | ||
id | ||
name | ||
} | ||
|
||
{ | ||
john: user(id: 1) { | ||
...UserF | ||
} | ||
jane: user(id: 2) { | ||
...UserF | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "programmatic-batching-example", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"start:mesh": "mesh dev", | ||
"start:api": "ts-node example-api/index.ts" | ||
}, | ||
"dependencies": { | ||
"@graphql-mesh/cli": "0.78.25", | ||
"@graphql-mesh/openapi": "0.33.20", | ||
"graphql": "16.6.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "29.0.3", | ||
"concurrently": "7.4.0", | ||
"ts-node": "10.9.1" | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/programmatic-batching/tests/__snapshots__/programmatic-batching.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Batching Example should generate correct schema 1`] = ` | ||
"schema { | ||
query: Query | ||
mutation: Mutation | ||
} | ||
type Mutation { | ||
usersByIds(input: UsersByIdRequest_Input): UsersByIdResponse | ||
} | ||
type Query { | ||
dummy: String | ||
user(id: Float!): User | ||
} | ||
type User { | ||
id: String | ||
name: String | ||
} | ||
input UsersByIdRequest_Input { | ||
ids: [Float] | ||
} | ||
type UsersByIdResponse { | ||
results: [User] | ||
}" | ||
`; | ||
|
||
exports[`Batching Example should give correct response for the batched example query: example-query-result 1`] = ` | ||
{ | ||
"data": { | ||
"jane": { | ||
"id": "2", | ||
"name": "Jane Doe", | ||
}, | ||
"john": { | ||
"id": "1", | ||
"name": "John Doe", | ||
}, | ||
}, | ||
} | ||
`; |
Oops, something went wrong.