@@ -16,7 +16,10 @@ const generatedSchema = new GraphQLSchema({
16
16
description : 'Elastic v5.0' ,
17
17
type : new GraphQLObjectType ( {
18
18
name : 'Elastic50' ,
19
- fields : new ElasticApiParser ( { version : '5_0' , prefix : 'Elastic50' } ) . run ( ) ,
19
+ fields : new ElasticApiParser ( {
20
+ version : '5_0' ,
21
+ prefix : 'Elastic50' ,
22
+ } ) . generateFieldMap ( ) ,
20
23
} ) ,
21
24
args : {
22
25
host : {
@@ -25,7 +28,8 @@ const generatedSchema = new GraphQLSchema({
25
28
} ,
26
29
} ,
27
30
resolve : ( src , args , context ) => {
28
- context . elasticClient = new elasticsearch . Client ( { // eslint-disable-line no-param-reassign
31
+ // eslint-disable-next-line no-param-reassign
32
+ context . elasticClient = new elasticsearch . Client ( {
29
33
host : args . host ,
30
34
apiVersion : '5.0' ,
31
35
log : 'trace' ,
@@ -38,7 +42,10 @@ const generatedSchema = new GraphQLSchema({
38
42
description : 'Elastic v2.4' ,
39
43
type : new GraphQLObjectType ( {
40
44
name : 'Elastic24' ,
41
- fields : new ElasticApiParser ( { version : '2_4' , prefix : 'Elastic24' } ) . run ( ) ,
45
+ fields : new ElasticApiParser ( {
46
+ version : '2_4' ,
47
+ prefix : 'Elastic24' ,
48
+ } ) . generateFieldMap ( ) ,
42
49
} ) ,
43
50
args : {
44
51
host : {
@@ -47,7 +54,8 @@ const generatedSchema = new GraphQLSchema({
47
54
} ,
48
55
} ,
49
56
resolve : ( src , args , context ) => {
50
- context . elasticClient = new elasticsearch . Client ( { // eslint-disable-line no-param-reassign
57
+ // eslint-disable-next-line no-param-reassign
58
+ context . elasticClient = new elasticsearch . Client ( {
51
59
host : args . host ,
52
60
apiVersion : '2.4' ,
53
61
} ) ;
@@ -59,7 +67,10 @@ const generatedSchema = new GraphQLSchema({
59
67
description : 'Elastic v1.7' ,
60
68
type : new GraphQLObjectType ( {
61
69
name : 'Elastic17' ,
62
- fields : new ElasticApiParser ( { version : '5_0' , prefix : 'Elastic17' } ) . run ( ) ,
70
+ fields : new ElasticApiParser ( {
71
+ version : '5_0' ,
72
+ prefix : 'Elastic17' ,
73
+ } ) . generateFieldMap ( ) ,
63
74
} ) ,
64
75
args : {
65
76
host : {
@@ -68,7 +79,8 @@ const generatedSchema = new GraphQLSchema({
68
79
} ,
69
80
} ,
70
81
resolve : ( src , args , context ) => {
71
- context . elasticClient = new elasticsearch . Client ( { // eslint-disable-line no-param-reassign
82
+ // eslint-disable-next-line no-param-reassign
83
+ context . elasticClient = new elasticsearch . Client ( {
72
84
host : args . host ,
73
85
apiVersion : '1.7' ,
74
86
} ) ;
@@ -80,17 +92,21 @@ const generatedSchema = new GraphQLSchema({
80
92
} ) ;
81
93
82
94
const server = express ( ) ;
83
- server . use ( '/' , graphqlHTTP ( {
84
- schema : generatedSchema ,
85
- graphiql : true ,
86
- context : {
87
- // elasticClient: new elasticsearch.Client({
88
- // host: 'http://localhost:9200',
89
- // apiVersion: '5.0',
90
- // log: 'trace',
91
- // }),
92
- } ,
93
- } ) ) ;
95
+ server . use (
96
+ '/' ,
97
+ graphqlHTTP ( {
98
+ schema : generatedSchema ,
99
+ graphiql : true ,
100
+ context : {
101
+ // // OR YOU MAY DEFINE elasticClient GLOBALLY
102
+ // elasticClient: new elasticsearch.Client({
103
+ // host: 'http://localhost:9200',
104
+ // apiVersion: '5.0',
105
+ // log: 'trace',
106
+ // }),
107
+ } ,
108
+ } )
109
+ ) ;
94
110
95
111
server . listen ( expressPort , ( ) => {
96
112
console . log ( `The server is running at http://localhost:${ expressPort } /` ) ;
0 commit comments