How to use the @apollo/gateway.ApolloGateway function in @apollo/gateway

To help you get started, we’ve selected a few @apollo/gateway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kriswep / graphql-microservices / service-gateway / src / index.js View on Github external
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}`);
  });
};
github webiny / webiny-js / examples / functions / code / api-gateway / src / handler.js View on Github external
//     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();
github juicycleff / ultimate-backend / apps / gateway-admin / src / simple.gateway.ts View on Github external
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,
github juicycleff / ultimate-backend / libs / nestjs-graphql-gateway / src / nestjs-graphql-distributed-gateway.module.ts View on Github external
__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,
github ExpediaGroup / graphql-component / test / examples / federation / gateway / index.js View on Github external
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}`)
});
github preply / graphene-federation / integration_tests / federation / src / index.ts View on Github external
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}`);
});
github magma / magma / symphony / federation / src / server.ts View on Github external
/**
 * 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}`)
})
github apollographql / federation-demo / gateway.js View on Github external
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}`);
  });
github Urigo / graphql-modules / examples / apollo-federation / gateway.ts View on Github external
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
  });
github webiny / webiny-js / packages / demo-api-gateway / src / handler.js View on Github external
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]);
                });
            }