-
Notifications
You must be signed in to change notification settings - Fork 42
/
apollo-server.mjs
97 lines (80 loc) · 1.95 KB
/
apollo-server.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { ApolloServer, gql } from 'apollo-server-express';
import express from 'express';
import cors from 'cors';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const typeDefs = gql`
type Member {
name: String!
section: String!
post: String!
linkedin: String!
instagram: String!
img: String!
rollNumber: String
branch: String!
location: String!
about: String
}
type BlogPost {
id: ID!
blog_title: String!
image: String!
author: String!
tags: [String!]!
description: String!
mdfile: String!
}
type Gallery {
id: ID!
image: String!
event: String
title: String
desc: String
set: String
}
type Query {
members: [Member]
blogPosts: [BlogPost]
gallery: [Gallery]
}
`;
const resolvers = {
Query: {
members: async () => {
const { profileDetails } = await import(pathToFileURL(path.resolve(__dirname, './data/member_data.mjs')).href);
return profileDetails;
},
blogPosts: async () => {
// Implement logic for fetching blogPosts data
return []; // Placeholder, replace with actual data fetching logic
},
gallery: async () => {
const { data } = await import(pathToFileURL(path.resolve(__dirname, './data/data.mjs')).href);
return data;
},
},
};
const app = express();
app.use(cors({
origin: '*',
}));
const startApolloServer = async () => {
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
});
await server.start();
server.applyMiddleware({ app, path: '/graphql' });
const PORT = 4000;
app.listen(PORT, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`);
});
};
startApolloServer().catch((err) => {
console.error('Error starting Apollo Server:', err);
});