Following the documentation for Apollo Server 2, there are errors when using registerServer and Typescript
import { ApolloServer } from 'apollo-server'
import express from 'express'
import { registerServer } from 'apollo-server-express'
const server = new ApolloServer({ // config })
const app = express()
registerServer({ server, app })
Gives the following error:
[tsl] ERROR in /app/server/index.ts(62,16)
TS2345: Argument of type '{ server: ApolloServer; app: Express; }' is not assignable to parameter of type 'ServerRegistration'.
Types of property 'server' are incompatible.
Type 'ApolloServer' is not assignable to type 'ApolloServerBase<Request>'.
Types have separate declarations of a private property 'schema'.
apollo-server 2.0.0-beta4
apollo-server-express 2.0.0-beta3
Temporary workaround is:
const server = new ApolloServer({}) as any
Super odd, we have that in the test, which are typescript, here. What's inside of your tsconfig?
Would love a PR with a failing test inside of the apollo-server package if you can manage!
Yeah, it's very weird, because clicking into the definition takes me directly to ApolloServerBase 馃.
Full tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"declaration": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": ["es2015", "es2016"],
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist/",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5",
"typeRoots": ["./node_modules/@types", "./app/@types"]
},
"exclude": ["lib/editor"]
}
Typescript 2.9.1.
This should be fixed after #1161
I'm experiencing this issue with ^2.13.0 versions:
TS2345: Argument of type 'typeof ApolloServer' is not assignable to parameter of type 'new (Config: any) => ApolloServerBase'.
Type 'ApolloServer' is not assignable to type 'ApolloServerBase'.
Types have separate declarations of a private property 'logger'.
@timohermans Can you open a separate issue referencing this?
Downgrading to
{
"apollo-server-express": "2.9.13",
"apollo-server-testing": "2.9.13
}
works for me.
Not sure why downgrading constitutes it being closed - this fails when trying to use Apollo server version 2 - trying to pass express app into applyMiddleware
server.applyMiddleware({ app, path });
Same here.
Versions:
"apollo-server-express": "^2.19.1",<br>
"express": "^4.17.1",
Implementation:
``const app = express();
const server = new ApolloServer({ typeDefs });
server.applyMiddleware({ app });
app.listen(port, (err: Error) => {
if (err) {
logger.error('something bad happened', err);
} else {
logger.info(server is listening on: ${port}`);
}
});
Error:
Type 'Express' is not assignable to type 'Application'.
Types of property 'engine' are incompatible...
```
Adding the object keys for applyMiddleware values solved it for me
instead of
...
const expressServer: express.Application = express();
...
const path: string = 'graphql';
apolloServer.applyMiddleware({ expressServer, path });
...
Do this (notice the object key-value pairs in the applyMiddleware object, not the just values)
...
const expressServer: express.Application = express();
...
const path: string = 'graphql';
apolloServer.applyMiddleware({ app: expressServer, path: path });
...
package.json
"apollo-server-express": "^2.19.1",
"express": "^4.17.1"
For me, this was due to mismatched @types/express across my application. I'm using [email protected] and [email protected] (the latest versions of both on npm, at the time of writing).
[email protected] uses @types/[email protected] (introduced in https://github.com/apollographql/apollo-server/commit/68043d377ec1a77bc2fcc8a4322186124abb734a). All other packages I'm using, including transitive dependencies of apollo-server-express and my root dependency of @types/express are all using @types/[email protected] (matching the express version).
@atkinchris's solution worked for me.
Thanks for saving the day!
I'm not sure if this is precisely that issue, but I definitely discovered in our app that some of the express-related DefinitelyTyped (@types) packages made backwards-incompatible changes and I needed to upgrade a bunch of them in parallel instead of just one. (Their deps on each other use very vague version specs, like * or something.)
Most helpful comment
I'm experiencing this issue with ^2.13.0 versions: