-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,744 additions
and
0 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 @@ | ||
node_modules |
Large diffs are not rendered by default.
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
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" | ||
} | ||
} |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
node ./src/index.js |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
npm i |
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,14 @@ | ||
const { ApolloServer } = require('apollo-server'); | ||
const typeDefs = require('./schema'); | ||
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}`); | ||
}); |
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,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; |
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,39 @@ | ||
const { gql } = require('apollo-server'); | ||
|
||
const typeDefs = gql` | ||
type Query { | ||
posts: [Post] | ||
post(id: ID!): Post | ||
users: [User] | ||
user(id: ID!): User | ||
} | ||
type Post { | ||
id: ID | ||
title: String | ||
body: String | ||
user: User | ||
} | ||
type User { | ||
id: ID | ||
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; |