How to use the @apollo/federation.buildFederatedSchema function in @apollo/federation

To help you get started, we’ve selected a few @apollo/federation 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 apollographql / federation-demo / services / inventory / index.js View on Github external
return {
        ...object,
        ...inventory.find(product => product.upc === object.upc)
      };
    },
    shippingEstimate(object) {
      // free for expensive items
      if (object.price > 1000) return 0;
      // estimate is based on weight
      return object.weight * 0.5;
    }
  }
};

const server = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs,
      resolvers
    }
  ])
});

server.listen({ port: 4004 }).then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

const inventory = [
  { upc: "1", inStock: true },
  { upc: "2", inStock: false },
  { upc: "3", inStock: true }
];
github Urigo / graphql-modules / examples / apollo-federation / services / inventory / index.ts View on Github external
...object,
          ...inventory.find(product => product.upc === object.upc)
        };
      },
      shippingEstimate(object) {
        // free for expensive items
        if (object.price > 1000) return 0;
        // estimate is based on weight
        return object.weight * 0.5;
      }
    }
  }
});

const server = new ApolloServer({
  schema: buildFederatedSchema([InventoryModule]),
  context: session => session
});

server.listen({ port: 4004 }).then(({ url }) => {
  // tslint:disable-next-line: no-console
  console.log(`🚀 Server ready at ${url}`);
});

const inventory = [{ upc: '1', inStock: true }, { upc: '2', inStock: false }, { upc: '3', inStock: true }];
github webiny / webiny-js / packages / api / src / graphql / prepareSchema.js View on Github external
// Fetch schema plugins again, in case there were new plugins registered in the meantime.
    const schemaPlugins = plugins.byType("graphql-schema");
    for (let i = 0; i < schemaPlugins.length; i++) {
        const { schema } = schemaPlugins[i];
        if (!schema) {
            continue;
        }

        if (typeof schema === "function") {
            schemaDefs.push(await schema({ plugins }));
        } else {
            schemaDefs.push(schema);
        }
    }

    return buildFederatedSchema([...schemaDefs]);
}
github TheBrainFamily / federation-testing-tool / index.js View on Github external
function buildLocalService(modules) {
  const schema = buildFederatedSchema(modules);
  return new LocalGraphQLDataSource(schema);
}
github kriswep / graphql-microservices / service-post / src / index.js View on Github external
import { ApolloServer } from 'apollo-server';
import { buildFederatedSchema } from '@apollo/federation';

import typeDefs from './schema/post';
import resolvers from './resolver';

const PORT = process.env.PORT || 3010;

const server = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs,
      resolvers
    }
  ])
});

server.listen(PORT).then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});
github 0xR / graphql-transform-federation / example / federation-server.ts View on Github external
const product = {
  id: '123',
  price: 899,
  weight: 100,
};

const resolvers = {
  Query: {
    findProduct() {
      return product;
    },
  },
};

const server = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs,
      resolvers,
    },
  ]),
});

server.listen({ port: 4002 }).then(({ url }: ServerInfo) => {
  console.log(`🚀 Federation server ready at ${url}`);
});
github kriswep / graphql-microservices / service-user / src / index.js View on Github external
import { ApolloServer } from 'apollo-server';
import { buildFederatedSchema } from '@apollo/federation';

import typeDefs from './schema/user';
import resolvers from './resolver';

const PORT = process.env.PORT || 3020;

const server = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs,
      resolvers
    }
  ])
});

server.listen(PORT).then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});
github webiny / webiny-js / packages / webiny-api / src / graphql / prepareSchema.js View on Github external
const schemaPlugins = getPlugins("graphql-schema");
    for (let i = 0; i < schemaPlugins.length; i++) {
        const { schema } = schemaPlugins[i];
        if (!schema) {
            continue;
        }

        if (typeof schema === "function") {
            schemaDefs.push(await schema(config));
        } else {
            schemaDefs.push(schema);
        }
    }

    return buildFederatedSchema([...schemaDefs]);
}
github juicycleff / ultimate-backend / libs / nestjs-graphql-gateway / src / graphql-distributed.factory.ts View on Github external
public async mergeOptions(options: GqlModuleOptions = {}): Promise {
    const resolvers = this.extendResolvers([
      this.resolversExplorerService.explore(),
      this.scalarsExplorerService.explore(),
      this.referencesExplorerService.explore(),
    ]);

    const federatedSchema = buildFederatedSchema([
      {
        typeDefs: gql`${options.typeDefs}`,
        resolvers,
      },
    ]);

    removeTempField(federatedSchema);
    return {
      ...options,
      typeDefs: undefined,
      schema: federatedSchema,
    };
  }