0

I am using Prisma with Javascript. It is working well. After upgrading to typescript, I have this error: GraphQLError: Syntax Error: Cannot parse the unexpected character ".".

// index.ts

const path = require('path')
const express = require('express')
const { importSchema } = require('graphql-import')
const { ApolloServer } = require('apollo-server-express')
const { Prisma } = require('prisma-binding')
const { makeExecutableSchema } = require('graphql-tools')
import resolvers from './resolvers'


const { directiveResolvers } = require('./directives')



const schema = makeExecutableSchema({
  typeDefs: './schema.graphql',
  resolvers,
  directiveResolvers
})

const server = new ApolloServer({
  debug: true,
  schema,
  formatError: error => error,

  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: path.join(__dirname, './generated-schema.graphql'),
      endpoint: 'http://localhost:4466/nacho/prod'
    })
  })
})

const app = express()

const port = 9000
app.listen({ port }, () => console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`))

// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "moduleResolution": "node",
    "module": "commonjs",
    "sourceMap": true,
    "allowJs": true,
    "rootDir": "src",
    "outDir": "dist",
    "lib": ["es2016", "esnext.asynciterable"]
  },
  "exclude": ["test", "dist"],
  "include": ["src/**/*"]
}

then I run tsc, it works, then node dist/index_server.js, I have this error:


/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/lexer.js:270
  throw (0, _syntaxError.syntaxError)(source, pos, unexpectedCharacterMessage(code));
  ^
GraphQLError: Syntax Error: Cannot parse the unexpected character ".".
    at syntaxError (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/error/syntaxError.js:15:10)
    at readToken (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/lexer.js:270:38)
    at Object.lookahead (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/lexer.js:54:43)
    at Object.advanceLexer [as advance] (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/lexer.js:44:33)
    at Parser.expectToken (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/parser.js:1399:19)
    at Parser.many (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/parser.js:1514:10)
    at Parser.parseDocument (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/parser.js:111:25)
    at Object.parse (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql/language/parser.js:36:17)
    at Object.buildSchemaFromTypeDefinitions (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:19:33)
    at makeExecutableSchema (/Users/alan/Documents/app/nacho/prismaTs/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
    at Object.<anonymous> (/Users/alan/Documents/app/nacho/prismaTs/dist/index_server.js:29:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

1 Answer 1

1

Check your './schema.graphql' for a syntax error?

Whatever IDE you're using should have a plugin for reading graphql schemas, and should highlight syntax errors.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! But it works in JavaScript. The issue is the file schema.graphql doesn't exits in the folder dist after the compilation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.