Skip to content

[2.6.0] TypeError: Cannot read property 'some' of undefined #2753

@wKovacs64

Description

@wKovacs64

Description

Just tried to update apollo-server-express from 2.5.1 → 2.6.0 but it's failing with the following:

TypeError: Cannot read property 'some' of undefined

  61 | 
> 62 |   const apolloServer = new ApolloServer({
     |                        ^

  at typeDefs.some.typeDef (node_modules/apollo-server-core/src/utils/isDirectiveDefined.ts:8:25)
      at Array.some (<anonymous>)
  at Object.<anonymous>.exports.isDirectiveDefined (node_modules/apollo-server-core/src/utils/isDirectiveDefined.ts:7:12)
  at new ApolloServerBase (node_modules/apollo-server-core/src/ApolloServer.ts:275:12)
  at new ApolloServer (node_modules/apollo-server-express/src/ApolloServer.ts:84:5)

It appears this only happens when importing typeDefs from an SDL file.

Reproduction

Glitch Remix (see server.js line 5, and open the logs)


Hacky Workaround

I modified isDirectiveDefined locally to include a truthiness check and that works, but I'm not sure if that's a real fix or just masking an actual problem (e.g. should all typeDef objects have a definitions property, or is undefined valid?).

packages/apollo-server-core/src/utils/isDirectiveDefined.ts#L8

  typeDefs.some(typeDef =>
-    typeDef.definitions.some(
+    typeDef.definitions && typeDef.definitions.some(
      definition =>

The code indicates typeDef is of type DocumentNode from graphql/language but I didn't see DocumentNode in the exported type definitions and ran out of time to chase that further. ¯\_(ツ)_/¯

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions