Skip to content

Commit 4303ad6

Browse files
author
amarflybot18
committed
change for es + fed
1 parent 3e0b145 commit 4303ad6

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"graphql-compose": "^7.9.0",
2626
"graphql-compose-elasticsearch": "^4.0.6",
2727
"graphql-playground-middleware-express": "^1.7.12",
28+
"graphql-tools": "^4.0.6",
2829
"graphql-voyager": "^1.0.0-rc.28",
2930
"pug": "^2.0.4"
3031
},

src/index.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import * as express from 'express';
22
import {default as expressPlayground} from "graphql-playground-middleware-express";
33
import {express as voyagerMiddleware} from "graphql-voyager/middleware";
44
import {altairExpress} from "altair-express-middleware";
5-
import {graphql, ObjectTypeComposer, schemaComposer} from "graphql-compose";
5+
import {graphql, ObjectTypeComposer, printSchema, schemaComposer} from "graphql-compose";
66
import {composeWithElastic} from "graphql-compose-elasticsearch";
77
import * as elasticsearch from "elasticsearch";
8-
import {ApolloServer} from "apollo-server-express";
8+
import {ApolloServer, gql} from "apollo-server-express";
99
import {buildFederatedSchema} from "./buildFederatedSchema";
1010

1111
const { GraphQLSchema, GraphQLObjectType } = graphql;
@@ -223,10 +223,6 @@ const EcommerceEsTC = composeWithElastic({
223223
elasticType: '_doc',
224224
elasticMapping: ecommerceMapping,
225225
elasticClient: elasticClient
226-
/*,
227-
// elastic mapping does not contain information about is fields are arrays or not
228-
// so provide this information explicitly for obtaining correct types in GraphQL
229-
pluralFields: ['skills', 'languages'],*/
230226
});
231227

232228
const ProxyTC = ObjectTypeComposer.createTemp(`type ProxyDebugType { source: JSON }`);
@@ -249,6 +245,23 @@ EcommerceEsTC.addRelation('showRelationArguments', {
249245
}
250246
});
251247

248+
let ContentTC = schemaComposer.createObjectTC(`
249+
extend type Content @key(fields: "id") {
250+
id: String! @external
251+
ecommerces: [ecommerceecommerce]
252+
}
253+
`);
254+
255+
let typesFieldsResolve = {
256+
'Content': {
257+
'ecommerces':(source, args, context, info) => {
258+
console.log("Here I am");
259+
return null;
260+
}
261+
}
262+
};
263+
schemaComposer.addResolveMethods(typesFieldsResolve);
264+
252265
const generatedSchema = new GraphQLSchema({
253266
query: new GraphQLObjectType({
254267
name: 'Query',
@@ -262,12 +275,7 @@ const generatedSchema = new GraphQLSchema({
262275
// check and change result here before returning it to user
263276
console.log(result);
264277
return result;
265-
}).getFieldConfig()/*,
266-
elastic75: elasticApiFieldConfig({
267-
host: 'http://elastic:changeme@localhost:9200',
268-
apiVersion: '7.5'/!*,
269-
log: 'trace',*!/
270-
})*/
278+
}).getFieldConfig()
271279
},
272280
}),
273281
});
@@ -293,9 +301,3 @@ app.listen(expressPort, () => {
293301
console.log(`The server is running at http://localhost:${expressPort}/`);
294302
});
295303

296-
297-
const inventory = [
298-
{ upc: "1", inStock: true },
299-
{ upc: "2", inStock: false },
300-
{ upc: "3", inStock: true }
301-
];

0 commit comments

Comments
 (0)