[英]GraphQLError: Syntax Error: Cannot parse the unexpected character “.”
I am currently using Apollo-server as my GraphQL server of choice and anytime I try to run tests I get the error indicated in the title.我目前正在使用 Apollo-server 作为我选择的 GraphQL 服务器,每当我尝试运行测试时,我都会收到标题中指示的错误。 However, my server implementation works as expected.但是,我的服务器实现按预期工作。
import 'cross-fetch/polyfill'; import ApolloClient, { gql } from 'apollo-boost'; const client = new ApolloClient({ uri: 'http://localhost:4000/', }); const USER = { invalidPassWord: { name: 'Gbolahan Olagunju', password: 'dafe', email: 'gbols@example.com' }, validCredentials: { name: 'Gbolahan Olagunju', password: 'dafeMania', email: 'gbols@example.com' }, usedEmail: { name: 'Gbolahan Olagunju', password: 'dafeMania', email: 'gbols@example.com' } }; describe('Tests the createUser Mutation', () => { test('should not signup a user with a password less than 8 characters', () => { const createUser = gql` mutation { createUser(data: USER.invalidPassWord){ token user { name password email id } } } ` client.mutate({ mutation: createUser }).then(res => console.log(res)); }) })
There is a problem with the document used in your test.您的测试中使用的文档有问题。 USER.invalidPassWord
is not valid GraphQL syntax. USER.invalidPassWord
不是有效的 GraphQL 语法。 Presumably you meant to use a template literal there to reference the USER
variable defined earlier.大概您打算在那里使用模板文字来引用之前定义的USER
变量。
Doing the GrapQL tutorial at在做 GrapQL 教程
https://www.howtographql.com/react-apollo/1-getting-started/https://www.howtographql.com/react-apollo/1-getting-started/
gives the same error.给出同样的错误。
I have razed the "same" issue at their site, though is the problem another in my case.我已经在他们的网站上解决了“相同”的问题,但在我的情况下是另一个问题。
https://github.com/howtographql/howtographql/issues/1047 https://github.com/howtographql/howtographql/issues/1047
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.