-
-
Notifications
You must be signed in to change notification settings - Fork 676
/
buildFederatedSchema.ts
26 lines (23 loc) · 922 Bytes
/
buildFederatedSchema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { buildSubgraphSchema } from "@apollo/subgraph";
import { type IResolvers, printSchemaWithDirectives } from "@graphql-tools/utils";
import gql from "graphql-tag";
import deepMerge from "lodash.merge";
import { type BuildSchemaOptions, buildSchema, createResolversMap } from "type-graphql";
export async function buildFederatedSchema(
options: Omit<BuildSchemaOptions, "skipCheck">,
referenceResolvers?: IResolvers,
) {
// Build TypeGraphQL executable schema
const schema = await buildSchema({
...options,
// Disable check to allow schemas without query, etc...
skipCheck: true,
});
// Build Apollo Subgraph schema
const federatedSchema = buildSubgraphSchema({
typeDefs: gql(printSchemaWithDirectives(schema)),
// Merge schema's resolvers with reference resolvers
resolvers: deepMerge(createResolversMap(schema) as any, referenceResolvers),
});
return federatedSchema;
}