-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathindex.ts
46 lines (39 loc) · 1.13 KB
/
index.ts
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
import express from 'express';
import graphqlHTTP from 'express-graphql';
import { graphql } from 'graphql-compose';
import { elasticApiFieldConfig } from '../../src'; // from 'graphql-compose-elasticsearch';
const { GraphQLSchema, GraphQLObjectType } = graphql;
const expressPort = process.env.port || process.env.PORT || 9201;
const generatedSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
elastic56: elasticApiFieldConfig({
host: 'http://user:pass@localhost:9200',
apiVersion: '5.6',
// log: 'trace',
}),
elastic68: elasticApiFieldConfig({
host: 'http://user:pass@localhost:9200',
apiVersion: '6.8',
// log: 'trace',
}),
elastic77: elasticApiFieldConfig({
host: 'http://user:pass@localhost:9200',
apiVersion: '7.7',
// log: 'trace',
}),
},
}),
});
const server = express();
server.use(
'/',
graphqlHTTP({
schema: generatedSchema,
graphiql: true,
})
);
server.listen(expressPort, () => {
console.log(`The server is running at http://localhost:${expressPort}/`);
});