Reputation: 2999
I have this function that I want to test, ina nodeJS project that uses Apollo Server's federated gateway implementation.
@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();
});
});
}
}
but when I test this function I have this error:
Error: Apollo Server requires either an existing schema, modules or typeDefs
I have tride to mock the schema doing this in 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);
but I have the same error
Upvotes: 4
Views: 1777
Reputation: 443
Update the apollo-server to least version and pass only gateway when create apollo server.
const server = new ApolloServer({
gateway
});
Upvotes: 1