forked from patrick91/apollo-federation-local-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountries-service.js
More file actions
29 lines (26 loc) · 848 Bytes
/
countries-service.js
File metadata and controls
29 lines (26 loc) · 848 Bytes
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
const { fetch } = require("cross-fetch");
const { print } = require("graphql");
const { wrapSchema, introspectSchema } = require("@graphql-tools/wrap");
const { transformSchemaFederation } = require("graphql-transform-federation");
const executor = async ({ document, variables }) => {
const query = print(document);
const fetchResult = await fetch("https://countries.trevorblades.com/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ query, variables }),
});
return fetchResult.json();
};
module.exports = async () => {
const schema = wrapSchema({
schema: await introspectSchema(executor),
executor,
});
return transformSchemaFederation(schema, {
Query: {
extend: true,
},
});
};