如何使用客户端?

2024-03-29 12:15:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过apollo客户端使用graphql。前端是Ember,后端是django和graphql服务器,在本教程(https://www.howtographql.com/graphql-python/0-introduction/)中实现。 Ember应用程序在4200端口上,graphql服务器在8000/graphql上代理(Ember s--proxyhttp://localhost:8000

我试着遵循这个指南(https://www.howtographql.com/ember-apollo/1-getting-started/),但是没有graphcool,因为我们有后端。你知道吗

在控制器中注册.js我有

import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Mutation from '../gql/mutation';

我这样给阿波罗注射的

export default Controller.extend({
    apollo: Ember.inject.service(),

突变是这样的

actions: {
    signUp() {
        let username = this.get('username');
        let password = this.get('password');
        let email = this.get('email');
        const credentials = { username, password, email };
        let mutation = Mutation.CREATE_USER;

        return this.get('apollo').mutate({mutation, credentials}, 'createUser').then(() => {
        this.set('username', '');
        this.set('email', '');
        this.set('password', '');
        console.log('user created successfully!');
    }).catch(error => console.log('ERROR!!!!111:', error));

单击表单中的提交按钮后,我收到了以下消息

POST http://localhost:4200/graphql 500 (Internal Server Error)
ServerParseError: Unexpected token < in JSON at position 0

我能做什么?你知道吗


Tags: fromimportgetemailserviceusernamepasswordthis
1条回答
网友
1楼 · 发布于 2024-03-29 12:15:32

好吧,有几件事可以帮你:

  • 如果您正在使用Chrome并转到开发工具,请转到网络->;预览。这应该会显示一些包含有关错误的更多信息的标记。你知道吗
  • 我不确定graphql突变文件是什么样子的,但您可能应该将其作为import mutation from ../gql/mutation导入。然后用this.get('apollo').mutate({mutation, credentials}, 'createUser')调用它
  • 确保graphql文件的相对路径正确
  • 我建议您将路线延长ComponentQueryManager,然后删除Apollo服务

相关问题 更多 >