@@ -16,7 +16,10 @@ const generatedSchema = new GraphQLSchema({
1616 description : 'Elastic v5.0' ,
1717 type : new GraphQLObjectType ( {
1818 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 ( ) ,
2023 } ) ,
2124 args : {
2225 host : {
@@ -25,7 +28,8 @@ const generatedSchema = new GraphQLSchema({
2528 } ,
2629 } ,
2730 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 ( {
2933 host : args . host ,
3034 apiVersion : '5.0' ,
3135 log : 'trace' ,
@@ -38,7 +42,10 @@ const generatedSchema = new GraphQLSchema({
3842 description : 'Elastic v2.4' ,
3943 type : new GraphQLObjectType ( {
4044 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 ( ) ,
4249 } ) ,
4350 args : {
4451 host : {
@@ -47,7 +54,8 @@ const generatedSchema = new GraphQLSchema({
4754 } ,
4855 } ,
4956 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 ( {
5159 host : args . host ,
5260 apiVersion : '2.4' ,
5361 } ) ;
@@ -59,7 +67,10 @@ const generatedSchema = new GraphQLSchema({
5967 description : 'Elastic v1.7' ,
6068 type : new GraphQLObjectType ( {
6169 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 ( ) ,
6374 } ) ,
6475 args : {
6576 host : {
@@ -68,7 +79,8 @@ const generatedSchema = new GraphQLSchema({
6879 } ,
6980 } ,
7081 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 ( {
7284 host : args . host ,
7385 apiVersion : '1.7' ,
7486 } ) ;
@@ -80,17 +92,21 @@ const generatedSchema = new GraphQLSchema({
8092} ) ;
8193
8294const 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+ ) ;
94110
95111server . listen ( expressPort , ( ) => {
96112 console . log ( `The server is running at http://localhost:${ expressPort } /` ) ;
0 commit comments