I'm using Readms's instructions for hapi.js:
const { ApolloServer, gql } = require('apollo-server-hapi');
const Hapi = require('hapi');
const typeDefs = gql`
type Query {
"A simple type for getting started!"
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'world'
}
};
async function StartServer() {
const server = new ApolloServer({ typeDefs, resolvers });
const app = new Hapi.server({
port: 3000
});
await server.applyMiddleware({
app
});
await server.installSubscriptionHandlers(app.listener);
await app.start();
}
StartServer().catch((error) => console.log(error));
it works like this, but if I change the name of app (for example app becomes testApp like this: const testApp = new Hapi.server({...) object it stop working and gives this error:
$ node server
TypeError: Cannot read property 'ext' of undefined
at ApolloServer.<anonymous> (node_modules\apollo-server-hapi\dist\ApolloServer.js:45:23)
at Generator.next (<anonymous>)
at node_modules\apollo-server-hapi\dist\ApolloServer.js:7:71
at new Promise (<anonymous>)
at __awaiter (node_modules\apollo-server-hapi\dist\ApolloServer.js:3:12)
at ApolloServer.applyMiddleware (node_modules\apollo-server-hapi\dist\ApolloServer.js:42:16)
at StartServer (server.js:73:18)
at Object.<anonymous> (server.js:82:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
I think this is strange, isn't it?
Hello @frederikhors , your issue is not strange at all but not related to apollo-server
The applyMiddleware method is using an options object instead of multiple parameters , you can do something like the snippet below to fix your problem:
async function StartServer() {
const server = new ApolloServer({ typeDefs, resolvers });
const testApp = new Hapi.server({
port: 3000
});
await server.applyMiddleware({
app: testApp
});
await server.installSubscriptionHandlers(app.listener);
await app.start();
}
Most helpful comment
Hello @frederikhors , your issue is not strange at all but not related to apollo-server
The applyMiddleware method is using an options object instead of multiple parameters , you can do something like the snippet below to fix your problem: