Skip to content

Instantly share code, notes, and snippets.

@erebus1
Created November 12, 2019 14:20
Show Gist options
  • Save erebus1/5ba1037b4b144db95b29fc94e9e2b5f2 to your computer and use it in GitHub Desktop.
Save erebus1/5ba1037b4b144db95b29fc94e9e2b5f2 to your computer and use it in GitHub Desktop.
const monolith_url: string = process.env.APOLLO_URL
const file_manager_url: string = process.env.FILE_MANAGER_URL
async function run() {
// logic on how extract files from file microservice
function getBatchFiles(context) {
return function batchFiles(keys: string[]): Promise<Array<{} | null>> {
return new Promise(function (resolve, reject) {
// query file microservice here
})
}
}
const createRemoteSchema = async (uri: string) => {
const http = new HttpLink({ uri, fetch });
const link = setContext((request, previousContext) => ({
headers: (previousContext.graphqlContext || {}).headers
})).concat(http);
try {
return makeRemoteExecutableSchema({
schema: await introspectSchema(link),
link
});
}catch (e) {
console.error(e);
}
};
const monolithSchema = await createRemoteSchema(apollo_url);
const fileSchema = await createRemoteSchema(file_manager_url);
let schemas:any = [];
schemas.push(monolithSchema);
schemas.push(fileSchema)
const linkSchemaDefs = `
extend type MessageNode {
file: [FileNode]
}
`;
// define how 2 schemas of monolith and filemanager will be combined
let schema = mergeSchemas({
schemas: schemas,
resolvers: mergeInfo => (resolvers)
});
const app = express();
const server = new ApolloServer({schema});
server.applyMiddleware({app});
app.listen(3000);
console.log('Server running. Open http://localhost:3000/graphql to run queries.');
}
run().catch(e => {
console.error(e, e.message, e.stack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment