我是graphQL的新手,我一直在尝试用它创建一个新的帐户对象。这是我现在的代码,但是它是graphQL的GUI,我一直收到“未知类型\” CreateAccountInput”错误。
schema.py
from authentication.models import Account
import graphene
from graphene import relay, ObjectType
from graphene_django import DjangoObjectType
from graphene import InputObjectType
class AccountGraphQL(DjangoObjectType):
class Meta:
model = Account
interfaces = (relay.Node, )
class Query(graphene.ObjectType):
username = graphene.String(argument=graphene.String(default_value="stranger"))
email = graphene.String(argument=graphene.String(default_value="stranger"))
password = graphene.String(argument=graphene.String(default_value="stranger"))
first_name = graphene.String(argument=graphene.String(default_value="stranger"))
info = graphene.String()
def def_resolve_create_account(self, info, argument):
return account.objects.create_user()
class CreateAccountInput(InputObjectType):
username = graphene.String(argument=graphene.String(default_value="stranger"))
email = graphene.String(argument=graphene.String(default_value="stranger"))
password = graphene.String(argument=graphene.String(default_value="stranger"))
first_name = graphene.String(argument=graphene.String(default_value="stranger"))
class CreateAccount(relay.ClientIDMutation):
class Input:
account = graphene.Argument(CreateAccountInput)
new_account = graphene.Field(AccountGraphQL)
@classmethod
def mutate_and_get_payload(cls, args, context, info):
account_data = args.get('account') # get account data from args
account = Account()
new_account = update_create_instance(account, account_data)
return cls(new_account=new_account)
class Mutation(ObjectType):
create_account = CreateAccount.Field()
schema = graphene.Schema(query=Query)
result = schema.execute('{ create_account (argument: "graphql"')
我的突变:
mutation CreateNewAccount($input: CreateAccountInput!) {
createAccount(input: $input) {
newAccount {
username
email
password
first_name
}
clientMutationId
}
}
我的查询
{"input": {"account":
{
"username": "graphql",
"email": "graphql@gmail.com",
"password": "graphql",
"first_name":"charles"
}
}}
我不确定这是什么问题,就我所担心的我已经定义了输入类型
答案 0 :(得分:0)