Skip to content

Commit

Permalink
fix(runtime): fix memoization logic on batching (#4605)
Browse files Browse the repository at this point in the history
* 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
ardatan and github-actions[bot] authored Sep 29, 2022
1 parent a5db45a commit 31a6471
Show file tree
Hide file tree
Showing 49 changed files with 493 additions and 81 deletions.
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_graphql-4605-dependencies.md
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`)
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`)
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`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_mysql-4605-dependencies.md
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`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_odata-4605-dependencies.md
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`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_postgraphile-4605-dependencies.md
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`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_runtime-4605-dependencies.md
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`)
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`)
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`)
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`)
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`)
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`)
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`)
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`)
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`)
6 changes: 6 additions & 0 deletions .changeset/@graphql-mesh_types-4605-dependencies.md
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`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_utils-4605-dependencies.md
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`)
5 changes: 5 additions & 0 deletions .changeset/lovely-shirts-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/runtime': patch
---

Fix memoization on batch delegation
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@ exports[`Neo4j should give correct response for example queries: example-query.g
"released": 1999n,
"tagline": "Welcome to the Real World",
"title": "The Matrix",
"votes": 2494n,
"votes": 2507n,
},
{
"peopleActedIn": [
Expand Down
20 changes: 20 additions & 0 deletions examples/programmatic-batching/.meshrc.yml
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
26 changes: 26 additions & 0 deletions examples/programmatic-batching/additional-resolvers.ts
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 }
}
`,
});
},
},
};
32 changes: 32 additions & 0 deletions examples/programmatic-batching/example-api/app.ts
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;
}
6 changes: 6 additions & 0 deletions examples/programmatic-batching/example-api/index.ts
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');
});
70 changes: 70 additions & 0 deletions examples/programmatic-batching/example-api/openapi.json
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"
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions examples/programmatic-batching/example-query.graphql
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
}
}
20 changes: 20 additions & 0 deletions examples/programmatic-batching/package.json
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"
}
}
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",
},
},
}
`;
Loading

0 comments on commit 31a6471

Please sign in to comment.