Getting the following error
Argument of type 'ApolloServer' is not assignable to parameter of type 'ApolloServerBase'.
Types have separate declarations of a private property 'logger'.
following setup:
const server = new ApolloServer({ ... });
const { query } = createTestClient(server);
Package
{
"apollo-server-express": "2.11.0",
"apollo-server-testing": "2.15.1"
}
Expected Behavior: Should work without error
Reference : #1140
This may not the most elegant solution, but I was able to get my resolver's integration test working (with jest as my test runner; using typescript) by setting the server instance to type "any" and the response to type "any".
const { query } = createTestClient(apolloServer as any);
const res: any = await query({ query: plansQuery });
Longer example:
it('fetches all plans', async () => {
const category1 = await categoryFactory();
await planFactory({ categoryId: category1.id });
await planFactory({ categoryId: category1.id });
const { query } = createTestClient(apolloServer as any);
const res: any = await query({ query: plansQuery });
expect(res.data.plans.length).toBe(2);
expect(res.data.errors).toBe(undefined);
});
I'm pretty sure these types of errors are caused by version mismatches from the apollo-server-* and apollo-server-testing packages that you are using. They change the typing between versions so different versions may declare and expect different types.
I had something very similar and solved it by making sure to specify the same version for the two in package.json and running npm/yarn install. I did need to restart my VSCode to get rid of the red squiggly for some reason.
There is no reason to use mismatched versions... apollo-server-testing should always defer to the version of the actual apollo-server package.
i've tried using the same version for all of my apollo-server-* => 2.17.0 packages but it still gives the same error
i've tried using the same version for all of my
apollo-server-* => 2.17.0packages but it still gives the same error
I'm on the same version as you (apollo-server-express) and it's working fine. Make sure to npm/yarn install after changing the versions (which afterwards should allow you to run tsc without error), and then possibly restart your IDE to get rid of the red squiggly.
Whats the verison of apollo-server-testing that you are using? I've locked all of the version, removed node_modules and reinstalled everything. But its still the same.
Whats the verison of
apollo-server-testingthat you are using? I've locked all of the version, removednode_modulesand reinstalled everything. But its still the same.
I am usingapollo-server-testing 2.16.0
It worked, just had to clean global cache and reinstall everything. guess something to do thing with old cache
Most helpful comment
I'm pretty sure these types of errors are caused by version mismatches from the
apollo-server-*andapollo-server-testingpackages that you are using. They change the typing between versions so different versions may declare and expect different types.I had something very similar and solved it by making sure to specify the same version for the two in
package.jsonand running npm/yarn install. I did need to restart my VSCode to get rid of the red squiggly for some reason.There is no reason to use mismatched versions...
apollo-server-testingshould always defer to the version of the actual apollo-server package.