-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
39 lines (36 loc) · 1.31 KB
/
index.js
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
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { stitchSchemas } = require('@graphql-tools/stitch');
const { RemoveObjectFieldDeprecations } = require('@graphql-tools/wrap');
const metadataSchema = require('./services/metadata/schema');
const productsSchema = require('./services/products/schema');
function makeGatewaySchema() {
return stitchSchemas({
subschemas: [
{
schema: metadataSchema,
transforms: [new RemoveObjectFieldDeprecations('gateway access only')],
batch: true,
merge: {
Product: {
// selectionSet: '{ upc }', << technically not necessary here!
fields: {
category: { selectionSet: '{ categoryId }', computed: true },
metadata: { selectionSet: '{ metadataIds }', computed: true },
},
fieldName: '_products',
key: ({ categoryId, metadataIds }) => ({ categoryId, metadataIds }),
argsFromKeys: (keys) => ({ keys }),
}
}
},
{
schema: productsSchema,
batch: true,
}
]
});
}
const app = express();
app.use('/graphql', graphqlHTTP({ schema: makeGatewaySchema(), graphiql: true }));
app.listen(4000, () => console.log('gateway running at http://localhost:4000/graphql'));