I've migrated Apollo Server from v3 to v4.
It works everything fine but I am not able to build the project in production mode because
there was several typescript errors into @apollo package. These are the last two left:
[tsl] ERROR in /home/xxx/projects/dashboard-api/node_modules/@apollo/server/src/ApolloServer.ts(238,53)
TS2345: Argument of type 'ApolloServerOptions<TContext>' is not assignable to parameter of type 'ApolloServerOptionsWithStaticSchema<TContext>'.
Type 'ApolloServerOptionsWithGateway<TContext>' is not assignable to type 'ApolloServerOptionsWithStaticSchema<TContext>'.
Type 'ApolloServerOptionsWithGateway<TContext>' is not assignable to type 'ApolloServerOptionsWithTypeDefs<TContext>'.
Property 'typeDefs' is optional in type 'ApolloServerOptionsWithGateway<TContext>' but required in type 'ApolloServerOptionsWithTypeDefs<TContext>'.
or
[tsl] ERROR in /home/xxx/projects/dashboard-api/node_modules/@apollo/server/src/ApolloServer.ts(1140,7)
TS2322: Type 'string | DocumentNode' is not assignable to type 'string'.
Type 'DocumentNode' is not assignable to type 'string'.
tsconfig.json
{
"compilerOptions": {
"incremental": true,
"lib": ["ES2020"],
"target": "ES2020",
"module": "commonjs",
"allowJs": false,
"sourceMap": true,
"outDir": "./build",
"strict": true,
"noImplicitAny": false,
"strictNullChecks": false,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"@/test/*": ["test/*"]
},
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"./node_modules",
"./node_modules/*",
"./node_modules/@types/node/index.d.ts",
]
}
webpack.common.js
module.exports = {
module: {
rules: [
{
test: /\.ts$/,
exclude: [path.resolve(__dirname, 'node_modules')],
use: 'ts-loader',
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'build'),
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
target: 'node',
}
webpack.production.js
const common = require('./webpack.common.js')
module.exports = merge(common, {
devtool: 'source-map',
entry: [path.join(__dirname, 'src/index.ts')],
externals: [nodeExternals({})],
mode: 'production',
plugins: [new CleanWebpackPlugin()],
})
package.json
{
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/graphql-iso-date": "^3.4.0",
"@types/jest": "^29.2.0",
"@types/node": "^14.14.41",
"@types/pg": "^8.6.5",
"@types/type-is": "^1.6.3",
"@types/webpack-env": "^1.18.0",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"apollo-server-testing": "^2.25.3",
"aws-sdk-mock": "^5.8.0",
"clean-webpack-plugin": "^4.0.0",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.0",
"eslint-plugin-standard": "^5.0.0",
"graphql-tag": "^2.12.6",
"husky": "^8.0.1",
"jest": "^29.2.0",
"jest-mock-extended": "^3.0.1",
"jest-transform-graphql": "^2.1.0",
"lint-staged": "^13.0.3",
"nock": "^13.2.9",
"nodemon": "^2.0.20",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@apollo/datasource-rest": "^4.3.2",
"@apollo/server": "^4.0.1",
"@hubspot/api-client": "^7.1.2",
"@sentry/node": "^7.15.0",
"@sentry/tracing": "^7.15.0",
"@shopify/shopify-api": "^5.2.0",
"@types/cors": "^2.8.12",
"@types/sanitize-html": "^2.6.2",
"apollo-datasource-http": "^0.21.0",
"apollo-server-caching": "^3.3.0",
"aws-sdk": "^2.1234.0",
"bcrypt": "^5.1.0",
"cors": "^2.8.5",
"date-fns": "^2.29.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"graphql": "^16.6.0",
"graphql-import-node": "0.0.5",
"graphql-iso-date": "^3.6.1",
"graphql-tools": "^8.3.6",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"pg": "^8.8.0",
"sanitize-html": "^2.7.2",
"yup": "^0.32.11"
},
"scripts": {
"start": "NODE_ENV=development nodemon",
"build": "NODE_ENV=production webpack --config webpack.production.js",
}
}
node version is v16.16.0
Is there any workaround to fix this problem?