GraphQLError:语法错误:无法解析意外的字符“。”

我当前正在使用Apollo服务器作为我选择的GraphQL服务器,并且每当我尝试运行测试时,都会出现标题中指示的错误。但是,我的服务器实现按预期工作。

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',usedEmail: {
    name: 'Gbolahan Olagunju',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));
  })
})

lttsusan 回答:GraphQLError:语法错误:无法解析意外的字符“。”

测试中使用的文档有问题。 USER.invalidPassWord是无效的GraphQL语法。大概您打算在此处使用模板文字来引用之前定义的USER变量。

本文链接:https://www.f2er.com/3081724.html

大家都在问