Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
let shapedModulesOrSDL: (GraphQLSchemaModule | DocumentNode)[] | DocumentNode;
if ('typeDefs' in modulesOrSDL) {
const { typeDefs, resolvers } = modulesOrSDL;
const augmentedTypeDefs = Array.isArray(typeDefs) ? typeDefs : [typeDefs];
shapedModulesOrSDL = augmentedTypeDefs.map((typeDefs, i) => {
const module: GraphQLSchemaModule = { typeDefs };
// add the resolvers to the first "module" in the array
if (i === 0 && resolvers) module.resolvers = resolvers;
return module;
});
} else {
shapedModulesOrSDL = modulesOrSDL;
}
const modules = modulesFromSDL(shapedModulesOrSDL);
let schema = buildSchemaFromSDL(
modules,
new GraphQLSchema({
query: undefined,
directives: [...specifiedDirectives, ...federationDirectives],
}),
);
// At this point in time, we have a schema to be printed into SDL which is
// representative of what the user defined for their schema. This is before
// we process any of the federation directives and add custom federation types
// so its the right place to create our service definition sdl.
//
// We have to use a modified printSchema from graphql-js which includes
// support for preserving the *uses* of federation directives while removing