apollo-server icon indicating copy to clipboard operation
apollo-server copied to clipboard

TS compilation error Argument of type '{ schema: GraphQLSchema; }' is not assignable to parameter of type 'ApolloServerExpressConfig'

Open Startouf opened this issue 5 years ago • 2 comments

Hello, I just started a fresh new project, installed express and apollo, and I run into the following error trying to start my Apollo server with an existing Schema, following the documentation I found there. Is there a conflict between apollo and graphql-tools ? I have no typescript errors in my VS Code but when I run the project with pnpm it crashes with the following error

src/appbase/apolloExpress.ts:23:43 - error TS2345: Argument of type '{ schema: GraphQLSchema; }' is not assignable to parameter of type 'ApolloServerExpressConfig'. Object literal may only specify known properties, and 'schema' does not exist in type 'ApolloServerExpressConfig'.

// index.ts
import { schema } from '../graphql/schema';
const apolloServer = new ApolloServer({ schema });

//../graphql/schema.ts
import { mergeSchemas, makeExecutableSchema } from 'graphql-tools';
...
export const schema: GraphQLSchema = mergeSchemas({
  schemas: [makeExecutableSchema({
    typeDefs,
    resolvers,
  })],
});

Relevant package versions

  • apollo-server-express: ^2.14.2
  • "graphql": "^15.0.0",
  • "graphql-tools": "^6.0.7",

Repro repo : HERE

This bug report should include:

  • [x] A short, but descriptive title. The title doesn't need "Apollo" in it.
  • [x] The package name and version of Apollo showing the problem.
  • [ ] If applicable, the last version of Apollo where the problem did not occur.
  • [x] The expected behavior.
  • [x] The actual behavior.
  • [x] A simple, runnable reproduction!

Startouf avatar Jun 04 '20 19:06 Startouf

The last known "good" version of apollo-server-express is 2.11.0, all versions after that have the exact same problem. A problem that has been reported before and has been there for weeks...

laddi-netapp avatar Jun 09 '20 13:06 laddi-netapp

Is there a workaround to this?

acrogenesis avatar Nov 30 '21 05:11 acrogenesis

I'm not sure what caused this, but we've refactored things a lot between AS2 and AS4 and passing schema to new ApolloServer definitely works now. Is it possible that this was a bug in the version of ts-node/typescript you were using back then? (I was able to reproduce it with your repository, but the types look fine in the versions of the packages installed in node_modules...)

glasser avatar Oct 21 '22 04:10 glasser