Apollo-server: createTestClient throws TypeError: Cannot read property 'bind' of undefined

Created on 23 Nov 2018  Â·  2Comments  Â·  Source: apollographql/apollo-server

I am trying to setup integration tests with jest as per the Apollo Server documentation. However, jest is hanging up on createTestClient.

User query › encountered a declaration exception

    TypeError: Cannot read property 'bind' of undefined


 24 |     },
      25 |   });
    > 26 |   const { query } = createTestClient(testServer);
         |                     ^
      27 |   it('Basic user query', async () => {
      28 |     const res = await query({ query: BASIC_QUERY });
      29 |     expect(res).toMatchSnapshot();

I am following this documentation along with the fullstack example:

import { server } from '../../schema';

const { createTestClient } = require('apollo-server-testing');

const { ApolloServer, gql } = require('apollo-server-express');

describe('User query', () => {
  const testServer = new ApolloServer({
    ...server,
    context: {
      user: {
        id: '[email protected]',
        email: '[email protected]',
      },
    },
  });
  const { query } = createTestClient(testServer);

Here is my package.json. I am using the latest stable release from jest:

{
  "name": "server",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "test": "jest",
    "build": "tsc",
    "start": "forever restart dist/index.js || forever start dist/index.js",
    "start2": "forever start dist/index.js",
    "stop": "forever stop dist/index.js",
    "tsc": "tsc",
    "generate-types": "echo 'Make sure you update typeDefs.graphql with the latest schema updates!!!' && cd src/graphqlgen && gg"
  },
  "main": "dist/index.js",
  "dependencies": {
    "apollo-datasource": "^0.2.0",
    "apollo-server": "^2.2.2",
    "apollo-server-express": "^2.0.0-rc.12",
    "body-parser": "^1.18.2",
    "busboy": "^0.2.14",
    "content-type": "^1.0.4",
    "express": "^4.16.2",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^1.0.4",
    "graphql": "^0.13.2",
    "graphql-import": "^0.7.1",
    "graphql-server-express": "^1.4.0",
    "graphql-subscriptions": "^0.5.8",
    "graphql-tools": "^4.0.3",
    "lodash": "^4.17.11",
    "moment": "^2.22.1",
    "neo4j-driver": "^1.6.1",
    "node-uuid": "^1.4.8",
    "subscriptions-transport-ws": "^0.9.9"
  },
  "devDependencies": {
    "@types/express": "^4.16.0",
    "@types/graphql": "^0.13.1",
    "@types/jest": "^23.3.9",
    "@types/neo4j": "^2.0.2",
    "@types/node": "^10.12.9",
    "@types/ws": "^5.1.2",
    "apollo": "^2.1.2",
    "apollo-server-testing": "^2.2.2",
    "babel-jest": "^23.6.0",
    "jest": "^23.6.0",
    "jest-cli": "^23.6.0",
    "regenerator-runtime": "^0.13.1",
    "ts-jest": "^23.10.5",
    "tslint": "^5.8.0",
    "typescript": "^3.1.6"
  },
  "jest": {
    "testPathIgnorePatterns": [
      "/node_modules/"
    ]
  },
  "private": true
}

Most helpful comment

I was having the exact same issue as you. Apollo is trying to use the method executeOperation but it seems this is only available from version 2.2.x onwards. Upgrading fixed it for me at least. Looks like you might need to upgrade apollo-server-express to 2.2.2.

All 2 comments

I was having the exact same issue as you. Apollo is trying to use the method executeOperation but it seems this is only available from version 2.2.x onwards. Upgrading fixed it for me at least. Looks like you might need to upgrade apollo-server-express to 2.2.2.

@spirift Nice find! Upgrading apollo-server-express to 2.2.2 did indeed fix the issue for me.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manuelfink picture manuelfink  Â·  3Comments

attdona picture attdona  Â·  3Comments

disyam picture disyam  Â·  3Comments

deathg0d picture deathg0d  Â·  3Comments

nevyn-lookback picture nevyn-lookback  Â·  3Comments