Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example js project #2

Merged
merged 17 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 4 additions & 0 deletions .github/workflows/benchmark-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
- name: Install Stable Toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- uses: actions/setup-node@v4
with:
node-version: 22
meskill marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Wrk
run: sudo apt-get update && sudo apt-get install -y wrk

Expand Down
1 change: 1 addition & 0 deletions projects/meskill/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
meskill marked this conversation as resolved.
Show resolved Hide resolved
1,622 changes: 1,622 additions & 0 deletions projects/meskill/package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions projects/meskill/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "meskill",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"apollo-server": "^3.13.0",
"axios": "^1.7.7",
"graphql": "^16.9.0"
}
}
9 changes: 9 additions & 0 deletions projects/meskill/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

node -v

npm i

node ./src/index.js
14 changes: 14 additions & 0 deletions projects/meskill/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema');
meskill marked this conversation as resolved.
Show resolved Hide resolved
const resolvers = require('./resolvers');

// Initialize Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers
});

// Start the server
server.listen({ port: 8000 }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
41 changes: 41 additions & 0 deletions projects/meskill/src/resolvers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const axios = require('axios');

const BASE_URL = 'http://localhost:3000'; // This is your upstream REST API

const resolvers = {
Query: {
// Resolver for fetching all posts
posts: async () => {
const response = await axios.get(`${BASE_URL}/posts`);
return response.data;
},

// Resolver for fetching a single post by ID
post: async (_, { id }) => {
const response = await axios.get(`${BASE_URL}/posts/${id}`);
return response.data;
},

// Resolver for fetching all users
users: async () => {
const response = await axios.get(`${BASE_URL}/users`);
return response.data;
},

// Resolver for fetching a single user by ID
user: async (_, { id }) => {
const response = await axios.get(`${BASE_URL}/users/${id}`);
return response.data;
}
},

Post: {
// Resolver for fetching the user of a post
user: async (parent) => {
const response = await axios.get(`${BASE_URL}/users/${parent.userId}`);
return response.data;
}
}
};

module.exports = resolvers;
39 changes: 39 additions & 0 deletions projects/meskill/src/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { gql } = require('apollo-server');

const typeDefs = gql`
type Query {
posts: [Post]
post(id: Int!): Post
users: [User]
user(id: Int!): User
}

type Post {
id: Int
title: String
body: String
user: User
}

type User {
id: Int
name: String
username: String
email: String
address: Address
phone: String
website: String
}

type Address {
zipcode: String
geo: Geo
}

type Geo {
lat: Float
lng: Float
}
`;

module.exports = typeDefs;