Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 }
];
...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 }];
// 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]);
}
function buildLocalService(modules) {
const schema = buildFederatedSchema(modules);
return new LocalGraphQLDataSource(schema);
}
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}`);
});
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}`);
});
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}`);
});
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]);
}
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,
};
}