我试图通过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
我能做什么?你知道吗
好吧,有几件事可以帮你:
import mutation from ../gql/mutation
导入。然后用this.get('apollo').mutate({mutation, credentials}, 'createUser')
调用它ComponentQueryManager
,然后删除Apollo服务相关问题 更多 >
编程相关推荐