Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let serviceName = Object.keys(service)[0];
if (!service[serviceName].resolvers) {
service[serviceName].addMocks = true;
}
serviceMap[serviceName] = buildLocalService([service[serviceName]]);
serviceMap[serviceName].__addMocks__ = service[serviceName].addMocks;
});
let mapForComposeServices = Object.entries(serviceMap).map(
([serviceName, service]) => ({
name: serviceName,
typeDefs: service.sdl()
})
);
let composed = composeAndValidate(mapForComposeServices);
if (composed.errors && composed.errors.length > 0) {
throw new Error(JSON.stringify(composed.errors));
}
return { schema: composed.schema, serviceMap };
};
): Promise {
let schema: GraphQLSchema;
const serviceMap = Object.fromEntries(
services.map(({ name, typeDefs, resolvers }) => {
return [
name,
new LocalGraphQLDataSource(
buildFederatedSchema([{ typeDefs, resolvers }]),
),
] as [string, LocalGraphQLDataSource];
}),
);
let errors: GraphQLError[];
({ schema, errors } = composeAndValidate(
Object.entries(serviceMap).map(([serviceName, service]) => ({
name: serviceName,
typeDefs: service.sdl(),
})),
));
if (errors && errors.length > 0) {
throw new GraphQLSchemaValidationError(errors);
}
const operationContext = buildOperationContext(schema, request.query);
const queryPlan = buildQueryPlan(operationContext);
const result = await executeQueryPlan(
queryPlan,
serviceMap,
protected createSchema(serviceList: ServiceDefinition[]) {
this.logger.debug(
`Composing schema from service list: \n${serviceList
.map(({ name, url }) => ` ${url || 'local'}: ${name}`)
.join('\n')}`,
);
const { schema, errors } = composeAndValidate(serviceList);
if (errors && errors.length > 0) {
if (this.experimental_didFailComposition) {
this.experimental_didFailComposition({
errors,
serviceList,
...(this.compositionMetadata && {
compositionMetadata: this.compositionMetadata,
}),
});
}
throw new GraphQLSchemaValidationError(errors);
}
this.createServices(serviceList);