-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (47 loc) · 1.51 KB
/
server.js
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
import { getauthor_loader, schema } from "./schema.js"
import postgres from "postgres"
import 'dotenv-safe/config.js'
import {
simpleEstimator,
createComplexityRule,
fieldExtensionsEstimator
} from 'graphql-query-complexity'
import express from 'express'
//import { createHandler } from 'graphql-http/lib/use/http'
import { graphqlHTTP } from 'express-graphql'
import requestLanguage from 'express-request-language'
const app = express()
export const sql = postgres({
host: process.env.HOST,
port: 5432,
database: process.env.DATABASE,
username: process.env.USER,
password: process.env.PASSWORD
})
app.use(
requestLanguage({
languages: ['en', 'fr'], // First locale becomes the default
}),
).use('/graphql', graphqlHTTP({
schema: schema,
context: {
authorloader: getauthor_loader()
},
validationRules: [
createComplexityRule({
estimators: [
// Configure your estimators
fieldExtensionsEstimator(),
simpleEstimator({ defaultComplexity: 1 })
],
maximumComplexity: 10,
variables: {},
onComplete: (complexity) => {
console.log('Query Complexity:', complexity)
},
}),
],
graphiql: true
}))
//app.get('/playground', graphQLPlayground({ endpoint: '/graphql' }))
app.listen(process.env.PORT, () => console.log('Server is running on http://localhost:'+process.env.PORT+'/graphql'))