-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (35 loc) · 1.07 KB
/
server.js
File metadata and controls
40 lines (35 loc) · 1.07 KB
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
const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema');
const resolvers = require('./resolvers');
const { formatError } = require('./utils/errorHandler');
require('dotenv').config();
// Import our data sources
const GitHubAPI = require('./datasources/githubAPI');
const StackOverflowAPI = require('./datasources/stackOverflowAPI');
const BlogAPI = require('./datasources/blogAPI');
// Set up data sources with caching
const dataSources = () => ({
githubAPI: new GitHubAPI(),
stackOverflowAPI: new StackOverflowAPI(),
blogAPI: new BlogAPI()
});
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources,
context: ({ req }) => {
// We can add authentication context here if needed later
return {};
},
formatError,
introspection: true,
playground: true,
cacheControl: {
defaultMaxAge: 3600, // 1 hour in seconds
},
});
const PORT = process.env.PORT || 4000;
server.listen(PORT).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
console.log(`📊 GraphQL Playground available at ${url}`);
});