apollo-server: [2.6.7] TypeError: Cannot read property 'some' of undefined

Hello!

First of all, thank you all for this great tool.

I’ve noticed this morning an error message when updating to v2.6.7.

package.json

{
    "apollo-server": "^2.6.7",
    "apollo-server-express": "^2.6.7",
    "graphql": "^14.4.1"
}

package.json where the issue does not occur:

{
    "apollo-server": "^2.6.4",
    "apollo-server-express": "^2.6.4",
    "graphql": "^14.3.1"
}

Actual behavior

/Users/tom/Development/backend/node_modules/apollo-server-core/dist/utils/isDirectiveDefined.js:11
        return typeDef.definitions.some(definition => definition.kind === language_1.Kind.DIRECTIVE_DEFINITION &&
                                   ^

TypeError: Cannot read property 'some' of undefined
    at typeDefs.some.typeDef (/Users/tom/Development/backend/node_modules/apollo-server-core/dist/utils/isDirectiveDefined.js:11:36)
    at Array.some (<anonymous>)
    at Object.exports.isDirectiveDefined (/Users/tom/Development/backend/node_modules/apollo-server-core/dist/utils/isDirectiveDefined.js:7:21)
    at new ApolloServerBase (/Users/tom/Development/backend/node_modules/apollo-server-core/dist/ApolloServer.js:146:39)
    at new ApolloServer (/Users/tom/Development/backend/node_modules/apollo-server-express/dist/ApolloServer.js:46:9)
    at Object.<anonymous> (/Users/tom/Development/backend/app/app.js:31:16)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/tom/Development/backend/index.js:6:13)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

Environment

  • node v8.16.0
  • macOS 10.14.5

One thing I noticed is that when I updated both apollo-server and apollo-server-express to v2.6.7 but left the graphql package at v14.3.1 the issue is still there.

Please let me know if there’s any additional info needed that I could provide.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Same for me. It works on 2.6.1, but doesn’t work on 2.9.7

Excellent issue and great research.

We also used the () => [Book] type exports and this caused issues for any version after 2.6.4

The correct solution IMO is to avoid this syntax for exporting types and just export types as DocumentNode or [DocumentNode, DocumentNode] and flatten them before passing them to typeDefs.

As another consideration, you might also try modules, which is only documented in this PR at the moment: https://github.com/apollographql/apollo-server/pull/2576/files#diff-2d27a587f5c91caac3eaf399fc6c3a83

Not sure if this is still the case, but there was a need to do something like the following when storing typeDef in multiple files:

// Book.js
const Book = gql`...`

// Author.js
const Book = require('./Book.js')
const Author = gql`
  type Author {
    firstName: String!
    lastName: String!
    books: [Book]!
}`
module.exports = () => [Author, Book]
`

Otherwise in Author.js it’d complain that the Book type was not specified, or whatever.

I will try just to simply do the following, without actually exporting types that my other type relies on, and then just combine them at the end with typeDefs:

const Author  = gql`...`
module.exports = Author;