Skip to content

Commit 1e1e45d

Browse files
author
amarflybot18
committed
Change without extend keyword
1 parent 4303ad6 commit 1e1e45d

File tree

3 files changed

+1828
-214
lines changed

3 files changed

+1828
-214
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"express": "^4.17.1",
2323
"express-graphql": "^0.9.0",
2424
"graphql": "^14.6.0",
25-
"graphql-compose": "^7.9.0",
26-
"graphql-compose-elasticsearch": "^4.0.6",
25+
"graphql-compose": "^7.11.0",
26+
"graphql-compose-elasticsearch": "^4.0.7",
2727
"graphql-playground-middleware-express": "^1.7.12",
2828
"graphql-tools": "^4.0.6",
2929
"graphql-voyager": "^1.0.0-rc.28",

src/index.ts

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ 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, printSchema, schemaComposer} from "graphql-compose";
5+
import {graphql, ObjectTypeComposer, printSchema, printSchemaComposer, SchemaComposer} from "graphql-compose";
66
import {composeWithElastic} from "graphql-compose-elasticsearch";
77
import * as elasticsearch from "elasticsearch";
88
import {ApolloServer, gql} from "apollo-server-express";
99
import {buildFederatedSchema} from "./buildFederatedSchema";
10+
import {collectFields} from "graphql/execution/execute";
1011

1112
const { GraphQLSchema, GraphQLObjectType } = graphql;
1213

@@ -210,7 +211,6 @@ const ecommerceMapping = {
210211
}
211212
};
212213

213-
214214
let elasticClient = new elasticsearch.Client({
215215
host: 'http://elastic:changeme@localhost:9200',
216216
apiVersion: '7.5',
@@ -245,23 +245,6 @@ EcommerceEsTC.addRelation('showRelationArguments', {
245245
}
246246
});
247247

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-
265248
const generatedSchema = new GraphQLSchema({
266249
query: new GraphQLObjectType({
267250
name: 'Query',
@@ -280,14 +263,47 @@ const generatedSchema = new GraphQLSchema({
280263
}),
281264
});
282265

266+
const schemaComposer = new SchemaComposer(generatedSchema);
267+
283268
schemaComposer.getOTC('ecommerceSearchHitItem')
284269
.removeField(['_index','_score','_shard','_node','_explanation','_version','_type'])
285270
.clearExtensions();
286271

272+
schemaComposer.addTypeDefs(`
273+
extend type Content @key(fields: "id") {
274+
id: ID! @external
275+
ecommerces: [ecommerceecommerce]
276+
}
277+
278+
extend type Director @key(fields: "id") {
279+
id: ID! @external
280+
ecommerceecommerceGeoips: [ecommerceecommerceGeoip]
281+
}
282+
`);
283+
const resolvers = {
284+
Content: {
285+
ecommerces(content) {
286+
return null;/*reviews.filter(review => review.product.upc === content.id);*/
287+
}
288+
},
289+
Content: {
290+
ecommerces(content) {
291+
return null;/*reviews.filter(review => review.product.upc === content.id);*/
292+
}
293+
}
294+
};
295+
296+
schemaComposer.addResolveMethods(resolvers);
297+
298+
let composer = printSchemaComposer(schemaComposer, {include: ["Content",
299+
"ecommerceSearchOutput", "ecommerceSearchOutputPagination", "ecommerceSearchHitItem"],
300+
exclude: ['Boolean', 'String']});
287301
const app = express();
288302

303+
console.log("template");
304+
let resolveMethods = schemaComposer.getResolveMethods();
289305
const server = new ApolloServer({
290-
schema: buildFederatedSchema(generatedSchema)
306+
schema: buildFederatedSchema([{typeDefs: gql(composer), resolvers: resolveMethods}])
291307
});
292308

293309
server.applyMiddleware({ app });
@@ -301,3 +317,33 @@ app.listen(expressPort, () => {
301317
console.log(`The server is running at http://localhost:${expressPort}/`);
302318
});
303319

320+
const usernames = [
321+
{ id: "1", username: "@ada" },
322+
{ id: "2", username: "@complete" }
323+
];
324+
const reviews = [
325+
{
326+
id: "1",
327+
authorID: "1",
328+
product: { upc: "1" },
329+
body: "Love it!"
330+
},
331+
{
332+
id: "2",
333+
authorID: "1",
334+
product: { upc: "2" },
335+
body: "Too expensive."
336+
},
337+
{
338+
id: "3",
339+
authorID: "2",
340+
product: { upc: "3" },
341+
body: "Could be better."
342+
},
343+
{
344+
id: "4",
345+
authorID: "2",
346+
product: { upc: "1" },
347+
body: "Prefer something else."
348+
}
349+
];

0 commit comments

Comments
 (0)