question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[javascript/graphql-apollo-server]: Unable to start example

See original GitHub issue

Hi there,

When I attempt to run this pared example as per this set of directions, I run into the following error in the command line:

  Missing required typegen import: Context

This also manifests in the GraphQL Playground when I attempt to run any query through the following:

Expand me for graphql response

{
  "error": {
    "errors": [
      {
        "message": "Cannot query field \"users\" on type \"Query\".",
        "locations": [
          {
            "line": 2,
            "column": 3
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"users\" on type \"Query\".",
              "    at Object.Field (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:213:34)",
              "    at Object.<anonymous> (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:119:42)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at process._tickCallback (internal/process/next_tick.js:68:7)"
            ]
          }
        }
      },
      {
        "message": "Cannot query field \"user\" on type \"Query\".",
        "locations": [
          {
            "line": 9,
            "column": 3
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"user\" on type \"Query\".",
              "    at Object.Field (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:213:34)",
              "    at Object.<anonymous> (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:119:42)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at process._tickCallback (internal/process/next_tick.js:68:7)"
            ]
          }
        }
      },
      {
        "message": "Cannot query field \"createUser\" on type \"Mutation\". Did you mean \"createDraft\"?",
        "locations": [
          {
            "line": 17,
            "column": 3
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"createUser\" on type \"Mutation\". Did you mean \"createDraft\"?",
              "    at Object.Field (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:213:34)",
              "    at Object.<anonymous> (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:119:42)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at process._tickCallback (internal/process/next_tick.js:68:7)"
            ]
          }
        }
      },
      {
        "message": "Cannot query field \"updateUser\" on type \"Mutation\".",
        "locations": [
          {
            "line": 25,
            "column": 3
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"updateUser\" on type \"Mutation\".",
              "    at Object.Field (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:213:34)",
              "    at Object.<anonymous> (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:119:42)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at process._tickCallback (internal/process/next_tick.js:68:7)"
            ]
          }
        }
      },
      {
        "message": "Cannot query field \"deleteUser\" on type \"Mutation\". Did you mean \"deleteOnePost\"?",
        "locations": [
          {
            "line": 33,
            "column": 3
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"deleteUser\" on type \"Mutation\". Did you mean \"deleteOnePost\"?",
              "    at Object.Field (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:324:29)",
              "    at Object.enter (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:375:25)",
              "    at visit (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/language/visitor.js:242:26)",
              "    at Object.validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/graphql/validation/validate.js:73:24)",
              "    at validate (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:213:34)",
              "    at Object.<anonymous> (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:119:42)",
              "    at Generator.next (<anonymous>)",
              "    at fulfilled (/Users/brianbancroft/programming/side-hustle/impressipies/graphql-apollo-server-api/node_modules/apollo-server-core/dist/requestPipeline.js:5:58)",
              "    at process._tickCallback (internal/process/next_tick.js:68:7)"
            ]
          }
        }
      }
    ]
  }
}

Other pertinent details:

This was attempted with the latest LTS versions of Node, 12.16.2 and 10.20.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:10

github_iconTop GitHub Comments

3reactions
jamesguancommented, Oct 11, 2020

In case you all haven’t already fixed this, you can resolve the issue by renaming context.js to context.ts (you may need to support typescript imports in your main app)

This doesn’t seem to be the right approach. Prisma should theoretically support both .js and .ts and should be language agnostic. The right approach would be to fix the code to accept both .js and .ts files.

3reactions
HendrikJancommented, May 14, 2020

@Benjaminryejones Thank you for the reply.

When I run npm run build the code runs without an error.
This is in line with your comment, because there is a file named “context.ts” in the /src folder.
This then generates a “context.js” file in the /dist folder.

When I then fun npm run start (which runs node dist/server), that is when the error appears.
It does not feel right to rename this file to “context.ts” at this point.

I guess the problem is in the schema.ts file at this piece of code:

typegenAutoConfig: {
    contextType: 'Context.Context',
    sources: [
      {
        source: '@prisma/client',
        alias: 'prisma',
      },
      {
        source: require.resolve('./context'), // <-- problem here, I guess
        alias: 'Context',
      },
    ],
  },

Is there a way to make npm run start (node dist/server) to run without the error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling - Apollo GraphQL Docs
Making errors actionable on the client and server. ... In the examples below, we use top-level await calls to start our server asynchronously....
Read more >
Can't create a new test Apollo Server - node.js - Stack Overflow
Turns out I need at least 1 @Query decorator in my resolvers, I just added a dummy resolver until I need an actual...
Read more >
apollo-server-express - npm
Production-ready Node.js GraphQL server for Express. Latest version: 3.11.1, last published: 2 months ago. Start using apollo-server-express ...
Read more >
Creating a GraphQL Server with Apollo
createProduct(product: ProductInput), this should create a product. Let's start a new file resolvers.js . At this point, we will keep things simple and...
Read more >
Top 5 apollo-server Code Examples - Snyk
To help you get started, we've selected a few apollo-server examples, based on popular ... Create GraphQL server const server = new ApolloServer({...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found