Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { ApolloServer } from 'apollo-server';
import { ApolloGateway } from '@apollo/gateway';
const PORT = process.env.PORT || 3000;
const postUrl = process.env.POST_URL || 'http://localhost:3010/graphql';
const userUrl = process.env.USER_URL || 'http://localhost:3020/graphql';
const gateway = new ApolloGateway({
serviceList: [
{ name: 'post', url: postUrl },
{ name: 'user', url: userUrl }
// more services here
]
});
const startGateway = async () => {
const { schema, executor } = await gateway.load();
const server = new ApolloServer({ schema, executor });
server.listen(PORT).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
};
// host = process.env.API_HOST;
// }
const services = [];
Object.keys(process.env).forEach(key => {
if (key.startsWith("SERVICE_")) {
services.push({
name: key.replace("SERVICE_", ""),
url: process.env[key]
});
}
});
console.log("services", services);
const gateway = new ApolloGateway({
serviceList: services,
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
willSendRequest({ request, context }) {
Object.keys(context.headers).forEach(key => {
if (context.headers[key]) {
request.http.headers.set(key, context.headers[key]);
}
});
}
});
}
});
const { schema, executor } = await gateway.load();
async function bootstrapSimple() {
const gateway = new ApolloGateway({
serviceList: [
{ name: 'auth', url: process.env.AUTH_ENDPOINT || 'http://localhost:9900/graphql' },
{ name: 'user', url: process.env.USER_ENDPOINT || 'http://localhost:9000/graphql' },
{ name: 'project', url: process.env.PROJECT_ENDPOINT || 'http://localhost:9100/graphql' },
{ name: 'tenant', url: process.env.TENANT_ENDPOINT || 'http://localhost:9200/graphql' },
{ name: 'payment', url: process.env.PAYMENT_ENDPOINT || 'http://localhost:9500/graphql' },
// more services
],
buildService({ url }) {
return new HeadersDatasource({ url });
},
});
const server = new ApolloServer({
gateway,
subscriptions: false,
__exposeQueryPlanExperimental,
debug,
// @ts-ignore
serviceList,
path,
disableHealthCheck,
onHealthCheck,
cors,
bodyParserConfig,
installSubscriptionHandlers,
buildService,
...rest
},
} = this;
const gateway = new ApolloGateway({
__exposeQueryPlanExperimental,
debug,
serviceList,
buildService,
});
this.apolloServer = new ApolloServer({
gateway,
...rest,
});
this.apolloServer.applyMiddleware({
app,
path,
disableHealthCheck,
onHealthCheck,
const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');
const gateway = new ApolloGateway({
serviceList: [
{ name: 'property', url: 'http://property:4000' },
{ name: 'reviews', url: 'http://reviews:4000' }
]
});
const server = new ApolloServer({
gateway,
subscriptions: false
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
});
import {ApolloServer} from 'apollo-server'
import {ApolloGateway} from '@apollo/gateway'
const serviceA_url: string = 'http://service_a:5000/graphql';
const serviceB_url: string = 'http://service_b:5000/graphql';
const serviceC_url: string = 'http://service_c:5000/graphql';
const serviceD_url: string = 'http://service_d:5000/graphql';
const gateway = new ApolloGateway({
serviceList: [
{ name: 'service_a', url: serviceA_url },
{ name: 'service_b', url: serviceB_url },
{ name: 'service_c', url: serviceC_url },
{ name: 'service_d', url: serviceD_url },
],
});
const server = new ApolloServer({
gateway,
subscriptions: false
});
server.listen(3000).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
/**
* Copyright (c) 2004-present Facebook All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
import { ApolloServer, ServerInfo } from 'apollo-server'
import { ApolloGateway } from '@apollo/gateway'
import config from './config'
const gateway = new ApolloGateway(config.gateway)
const server = new ApolloServer({
gateway,
subscriptions: false,
...config.server,
})
server.listen(...config.listen).then(({ url }: ServerInfo) => {
console.log(`🚀 Server ready at ${url}`)
})
const { ApolloServer } = require("apollo-server");
const { ApolloGateway } = require("@apollo/gateway");
const gateway = new ApolloGateway({
serviceList: [
{ name: "accounts", url: "http://localhost:4001/graphql" },
{ name: "reviews", url: "http://localhost:4002/graphql" },
{ name: "products", url: "http://localhost:4003/graphql" },
{ name: "inventory", url: "http://localhost:4004/graphql" }
]
});
(async () => {
const { schema, executor } = await gateway.load();
const server = new ApolloServer({ schema, executor });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
import { ApolloServer } from 'apollo-server';
import { ApolloGateway } from '@apollo/gateway';
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001/graphql' },
{ name: 'reviews', url: 'http://localhost:4002/graphql' },
{ name: 'products', url: 'http://localhost:4003/graphql' },
{ name: 'inventory', url: 'http://localhost:4004/graphql' }
]
});
(async () => {
const { schema, executor } = await gateway.load();
const server = new ApolloServer({
schema,
executor,
context: session => session
});
const { ApolloGateway, RemoteGraphQLDataSource } = require("@apollo/gateway");
import { ApolloServer } from "apollo-server-lambda";
import createConfig from "demo-service-config";
const host = process.env.FUNCTIONS_HOST;
const gateway = new ApolloGateway({
serviceList: [
{ name: "pageBuilder", url: host + "/function/page-builder" },
{ name: "security", url: host + "/function/security" },
{ name: "files", url: host + "/function/files" },
{ name: "i18n", url: host + "/function/i18n" },
{ name: "forms", url: host + "/function/forms" }
//{ name: "headless", url: host + "/function/headless" }
],
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
willSendRequest({ request, context }) {
Object.keys(context.headers).forEach(key => {
request.http.headers.set(key, context.headers[key]);
});
}