1

所以当我启动我的服务器时,我得到了这个错误列表

/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:966 throw (0, _error.syntaxError)(lexer.source, token.start, 'Expected ' + kind + ', found ' + (0, _lexer.getTokenDesc)(token)); ^ GraphQLError at syntaxError (/Users/charlie/workspace/HackQLServer/node_modules/graphql/error/syntaxError.js:28:15) at expect (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:966:32) at parseName (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:88:15) at parseInputValueDef (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:743:14) at many (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:1015:16) at parseArgumentDefs (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:735:10) at parseFieldDefinition (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:714:14) at any (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:1002:16) at parseObjectTypeDefinition (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:683:16) at parseTypeSystemDefinition (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:607:16) at parseDefinition (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:148:16) at parseDocument (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:106:22) at Object.parse (/Users/charlie/workspace/HackQLServer/node_modules/graphql/language/parser.js:43:10) at buildSchemaFromTypeDefinitions (/Users/charlie/workspace/HackQLServer/node_modules/graphql-tools/src/schemaGenerator.ts:145:37) at _generateSchema (/Users/charlie/workspace/HackQLServer/node_modules/graphql-tools/src/schemaGenerator.ts:72:18) at makeExecutableSchema (/Users/charlie/workspace/HackQLServer/node_modules/graphql-tools/src/schemaGenerator.ts:97:20)

随着这一切的出现。我真的不明白我的错误在哪里。这是我的架构文件,我认为错误是

const typeDefinitions = `
    type Author {
      id: Int
      firstName: String
      lastName: String
      posts: [Post]
    }

    type Post {
      id: Int
      title: String
      text: String
      author: Author
    }

type Query {
  author(firstName: String, lastName: String): Author
  allPosts(): [Post!]!
}

schema {
  query: Query
}`

export default [typeDefinitions]

如果您认为错误可能源于它,这也是我的解析器文件

import { Author, Post } from './connectors'

const resolvers = {
  Query: {
    author: (root, args) => {
      return Author.find({ where: args })
    },
    allPosts: (root, args) => {
      return Post.findAll()
    },
    allAuthors: (root, args) => {
      return Author.findAll()
    }
  },
  Author: {
    posts: (author) => {
      return author.getPosts()
    }
  },
  Post: {
    author: (post) => {
      return post.getAuthor()
    }
  }
}

export default resolvers

如果您看到任何内容,请告诉我,因为我无法弄清楚这一点。我还在使用 Sequelize 与 sqlite 进行数据库连接,以防您想知道我的模型查询的语法可能是什么。

4

1 回答 1

6

我认为错误在这一行

type Query { author(firstName: String, lastName: String): Author allPosts(): [Post!]! }

由于allPost没有参数,因此不需要 parentesis。它应该是

type Query { author(firstName: String, lastName: String): Author allPosts: [Post!]! }

遇到这样的神秘错误, throw (0, _error.syntaxError)(lexer.source, token.start, 'Expected ' + kind + ', found ' + (0, _lexer.getTokenDesc)(token))很可能是由架构文件中的无效语法引起的

于 2017-03-24T19:25:23.083 回答