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.

Getting error when first starting server in the tutorial

See original GitHub issue

I’m sure it’s something I’m doing wrong, but I’ve just started the tutorial and when I first try to start the server I get

type Launch { ^^^^^^

SyntaxError: Unexpected identifier at new Script (vm.js:74:7) at createScript (vm.js:246:10) at Object.runInThisContext (vm.js:298:10) at Module._compile (internal/modules/cjs/loader.js:657:28) at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:20:18) [nodemon] app crashed - waiting for file changes before starting…

My schema.js file is

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

const typeDefs = gql``

module.exports = typeDefs;


type Launch {
  id: ID!
    site: String
  mission: Mission
  rocket: Rocket
  isBooked: Boolean!
}

type Rocket {
  id: ID!
    name: String
  type: String
}

type User {
  id: ID!
    email: String!
    trips: [Launch]!
}

type Mission {
  name: String
  missionPatch(size: PatchSize): String
}

enum PatchSize {
  SMALL
  LARGE
}

type Mutation {
  # if false, booking trips failed -- check errors
  bookTrips(launchIds: [ID]!): TripUpdateResponse!

    # if false, cancellation failed -- check errors
  cancelTrip(launchId: ID!): TripUpdateResponse!

    login(email: String): String # login token
}

type Query {
  launches: [Launch]!
    launch(id: ID!): Launch
  # Queries for the current user
  me: User
}

and index.js is


const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema');

const server = new ApolloServer({ typeDefs });

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Not sure where the error lies as I was simply copying code from the tutorial…thanks for any clues.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

9reactions
zachdixoncommented, Feb 27, 2019

All your graphql code (type, enum, etc) needs to be within the gql template string where typeDefs is defined. I ran into this as well going through the tutorial since it doesn’t mention it.

3reactions
httpJunkiecommented, Nov 6, 2019

As per the documentation says (which I also missed the first time):

Our schema will be based on these features. In src/schema.js, import gql from Apollo Server and create a variable called typeDefs for your schema. Your schema will go inside the gql function (between the backticks in this portion: gql``).

Your final file schema.js file should look like this:

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

const typeDefs = gql`
  type Query {
    launches: [Launch]!
    launch(id: ID!): Launch
    # Queries for the current user
    me: User
  }

  type Mutation {
    # if false, booking trips failed -- check errors
    bookTrips(launchIds: [ID]!): TripUpdateResponse!

    # if false, cancellation failed -- check errors
    cancelTrip(launchId: ID!): TripUpdateResponse!

    login(email: String): String # login token
  }

  type TripUpdateResponse {
    success: Boolean!
    message: String
    launches: [Launch]
  }

  type Launch {
    id: ID!
    site: String
    mission: Mission
    rocket: Rocket
    isBooked: Boolean!
  }

  type Rocket {
    id: ID!
    name: String
    type: String
  }

  type User {
    id: ID!
    email: String!
    trips: [Launch]!
  }

  type Mission {
    name: String
    missionPatch(size: PatchSize): String
  }

  enum PatchSize {
    SMALL
    LARGE
  }  
`;

module.exports = typeDefs;
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix the JNI Error in Java (Java 16 Tutorial) - YouTube
Start a 24 hour Minecraft server without any issues at Apex Minecraft Hosting in under 5 minutes! https://TheBreakdown.xyz/Apex Download the ...
Read more >
Cannot GET / Nodejs Error - Stack Overflow
After starting the server with node server.js I'm getting an error stating Cannot GET / when I access localhost:5000 and I just wondered...
Read more >
How To Troubleshoot Common Site Issues on a Linux Server
Everybody runs into issues with their website at one point or another. This guide will help you troubleshoot some common issues and get...
Read more >
Tutorials/Setting up a server - Minecraft Wiki - Fandom
Double click the file to start your server. You may get a "Class_Not_Found" and ServerGuiConcole error, just ignore these errors and you should...
Read more >
Starting the Server | Vault - HashiCorp Developer
If the output looks different, restart the dev server and try again. The only reason these would ever be different is if you're...
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