-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into k6_migration
- Loading branch information
Showing
19 changed files
with
265 additions
and
222 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,13 +1,72 @@ | ||
const express = require('express'); | ||
const express = require("express"); | ||
const axios = require("axios"); | ||
const DataLoader = require("dataloader"); | ||
const { Agent } = require("http"); | ||
|
||
// Create a new axios instance with connection pooling. | ||
const httpAgent = new Agent({ keepAlive: true }); | ||
const axiosInstance = axios.create({ | ||
httpAgent, | ||
}); | ||
|
||
const app = express(); | ||
const port = 4000; | ||
|
||
app.use(express.json()); | ||
|
||
async function batchUsers(usersIds) { | ||
const requests = usersIds.map(async (id) => { | ||
const response = await axiosInstance.get( | ||
`http://jsonplaceholder.typicode.com/users/${id}`, | ||
{ | ||
proxy: { | ||
protocol: "http", | ||
host: "127.0.0.1", | ||
port: 3000, | ||
}, | ||
}, | ||
); | ||
return response.data; | ||
}); | ||
return await Promise.all(requests); | ||
} | ||
|
||
// Route to greet | ||
app.post('/greet', (req, res) => { | ||
res.json('Hello World!'); | ||
}); | ||
|
||
// Route to fetch posts | ||
app.post('/posts', async (req, res) => { | ||
try { | ||
const response = await axiosInstance.get('http://jsonplaceholder.typicode.com/posts', { | ||
proxy: { | ||
protocol: "http", | ||
host: "127.0.0.1", | ||
port: 3000, | ||
}, | ||
}); | ||
let posts = response.data; | ||
|
||
if (req.body.request_query.includes("user")) { | ||
const userLoader = new DataLoader(batchUsers, { | ||
batchScheduleFn: (callback) => setTimeout(callback, 1), | ||
}); | ||
posts = await Promise.all(posts.map(async (post) => { | ||
const user = await userLoader.load(post.userId); | ||
return { | ||
...post, | ||
user, | ||
}; | ||
})) | ||
} | ||
|
||
res.json(posts); | ||
} catch (error) { | ||
res.json(error); | ||
} | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Greet action handler running on port ${port}`); | ||
console.log(`Handler server running on port ${port}`); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
type Query { | ||
greet: String! | ||
posts: [Post!]! | ||
} | ||
|
||
type Post { | ||
id: ID! | ||
userId: ID! | ||
title: String! | ||
body: String! | ||
user: User | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: String! | ||
email: String! | ||
phone: String! | ||
website: 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
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 |
---|---|---|
@@ -1,14 +1 @@ | ||
- name: default | ||
kind: postgres | ||
configuration: | ||
connection_info: | ||
use_prepared_statements: true | ||
database_url: | ||
from_env: HASURA_GRAPHQL_DATABASE_URL | ||
isolation_level: read-committed | ||
pool_settings: | ||
connection_lifetime: 600 | ||
retries: 1 | ||
idle_timeout: 180 | ||
max_connections: 50 | ||
tables: "!include default/tables/tables.yaml" | ||
[] |
7 changes: 0 additions & 7 deletions
7
graphql/hasura/metadata/databases/default/tables/public_posts.yaml
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
graphql/hasura/metadata/databases/default/tables/public_users.yaml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
de25bba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ posts { id userId title user { id name email }}}
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
{ posts { title }}
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
{ greet }
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx
-nan
-nan
-nanx