У меня есть эта функция, которую я хочу протестировать, в проекте nodeJS, который использует реализацию федеративного шлюза Apollo Server.
@Service()
export class Server {
constructor();
}
async startAsync(): Promise<void> {
await this.createApolloGateway();
}
private async createApolloGateway(): Promise<void> {
const gateway = new ApolloGateway({
serviceList: [{ name: 'products', url: 'https://products-service.dev/graphql' },
{ name: 'reviews', url: 'https://reviews-service.dev/graphql' }]});
const {schema, executor} = await gateway.load();
const server = new ApolloServer({schema, executor});
return new Promise((resolve, _) => {
server.listen(8080).then(({url}) => {
resolve();
});
});
}
}
, но когда я тестирую эту функцию, у меня появляется эта ошибка:
Error: Apollo Server requires either an existing schema, modules or typeDefs
У меня есть трид, чтобы смоделировать схему, делая это в рамках Jest Framework
apolloGateway = createMockInstance(ApolloGateway);
it('should start an http server', async () => {
// Arrange
const server = new Server(configurationService, loggerService);
const schema = `
type User {
id: ID!
name: String
lists: [List]
}
type RootQuery {
user(id: ID): User
}
schema {
query: RootQuery
}
`;
apolloGateway.load = jest.fn().mockReturnValue(schema);
// Act
await server.startAsync();
// Assert
await expect(server).not.toBeNull;
}, 30000);
но у меня такая же ошибка