Graphql mutation error: "Field 'createUser' is missing required arguments: input"
Graphql mutation error: "Field 'createUser' is missing required arguments: input"
我正在尝试按照这篇关于如何使用 GraphQl https://www.howtographql.com/graphql-ruby/4-authentication
在 rails 服务器上创建变更的文章进行操作
但是,我卡在了 CreateUser Mutation 步骤,在 GraphiQL 中尝试时我得到了以下错误散列:
{
"errors": [
{
"message": "Field 'createUser' is missing required arguments: input",
"locations": [
{
"line": 45,
"column": 3
}
],
"path": [
"mutation CreateUser",
"createUser"
],
"extensions": {
"code": "missingRequiredArguments",
"className": "Field",
"name": "createUser",
"arguments": "input"
}
},
{
"message": "Field 'createUser' doesn't accept argument 'username'",
"locations": [
{
"line": 46,
"column": 5
}
],
"path": [
"mutation CreateUser",
"createUser",
"username"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "createUser",
"typeName": "Field",
"argumentName": "username"
}
},
{
"message": "Field 'createUser' doesn't accept argument 'authProvider'",
"locations": [
{
"line": 47,
"column": 5
}
],
"path": [
"mutation CreateUser",
"createUser",
"authProvider"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "createUser",
"typeName": "Field",
"argumentName": "authProvider"
}
},
{
"message": "Variable $username is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "username"
}
},
{
"message": "Variable $email is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "email"
}
},
{
"message": "Variable $password is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "password"
}
}
]
}
我只是按照文章中的代码,我的文件:
create_user.rb
module Mutations
class CreateUser < BaseMutation
# often we will need input types for specific mutation
# in those cases we can define those input types in the mutation class itself
class AuthProviderSignupData < Types::BaseInputObject
argument :credentials, Types::AuthProviderCredentialsInput, required: false
end
argument :username, String, required: true
argument :auth_provider, AuthProviderSignupData, required: false
type Types::UserType
def resolve(username: nil, auth_provider: nil)
User.create!(
username: username,
email: auth_provider&.[](:credentials)&.[](:email),
password: auth_provider&.[](:credentials)&.[](:password)
)
end
end
end
user_type.rb
module Types
class UserType < BaseObject
field :id, ID, null: false
field :email, String, null: false
field :username, String, null: false
field :photo, String, null: true
field :phone, String, null: false
field :island, IslandType, null: false, method: :island
field :archipel, ArchipelType, null: false, method: :archipel
field :created_at, String, null: false
field :updated_at, String, null: false
end
end
我不知道这个 'input' 东西是从哪里来的。
我在不知不觉中用一个使用 Relay 的配置初始化了我的项目。
通过在我的 **_schema.rb 文件中注释这段代码,它再次起作用了。
# Opt in to the new runtime (default in future graphql-ruby versions)
# use GraphQL::Execution::Interpreter
# use GraphQL::Analysis::AST
# Add built-in connections for pagination
# use GraphQL::Pagination::Connections
以及 base_mutation.rb 中的这些行并用这些替换。
# class BaseMutation < GraphQL::Schema::RelayClassicMutation
# argument_class Types::BaseArgument
# field_class Types::BaseField
# input_object_class Types::BaseInputObject
# object_class Types::BaseObject
# end
class BaseMutation < GraphQL::Schema::Mutation
null false
end
如果您对注释字段不感兴趣...我 运行 遇到了同样的错误。无论出于何种原因 input
是您将参数作为 hash/object.
传递给的键的名称
使用本教程的示例:https://www.howtographql.com/graphql-ruby/3-mutations/
mutation {
createLink(input: {
url: "foo",
description:"bar"
}) {
url
description
}
}
我正在尝试按照这篇关于如何使用 GraphQl https://www.howtographql.com/graphql-ruby/4-authentication
在 rails 服务器上创建变更的文章进行操作但是,我卡在了 CreateUser Mutation 步骤,在 GraphiQL 中尝试时我得到了以下错误散列:
{
"errors": [
{
"message": "Field 'createUser' is missing required arguments: input",
"locations": [
{
"line": 45,
"column": 3
}
],
"path": [
"mutation CreateUser",
"createUser"
],
"extensions": {
"code": "missingRequiredArguments",
"className": "Field",
"name": "createUser",
"arguments": "input"
}
},
{
"message": "Field 'createUser' doesn't accept argument 'username'",
"locations": [
{
"line": 46,
"column": 5
}
],
"path": [
"mutation CreateUser",
"createUser",
"username"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "createUser",
"typeName": "Field",
"argumentName": "username"
}
},
{
"message": "Field 'createUser' doesn't accept argument 'authProvider'",
"locations": [
{
"line": 47,
"column": 5
}
],
"path": [
"mutation CreateUser",
"createUser",
"authProvider"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "createUser",
"typeName": "Field",
"argumentName": "authProvider"
}
},
{
"message": "Variable $username is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "username"
}
},
{
"message": "Variable $email is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "email"
}
},
{
"message": "Variable $password is declared by CreateUser but not used",
"locations": [
{
"line": 44,
"column": 1
}
],
"path": [
"mutation CreateUser"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "password"
}
}
]
}
我只是按照文章中的代码,我的文件:
create_user.rb
module Mutations
class CreateUser < BaseMutation
# often we will need input types for specific mutation
# in those cases we can define those input types in the mutation class itself
class AuthProviderSignupData < Types::BaseInputObject
argument :credentials, Types::AuthProviderCredentialsInput, required: false
end
argument :username, String, required: true
argument :auth_provider, AuthProviderSignupData, required: false
type Types::UserType
def resolve(username: nil, auth_provider: nil)
User.create!(
username: username,
email: auth_provider&.[](:credentials)&.[](:email),
password: auth_provider&.[](:credentials)&.[](:password)
)
end
end
end
user_type.rb
module Types
class UserType < BaseObject
field :id, ID, null: false
field :email, String, null: false
field :username, String, null: false
field :photo, String, null: true
field :phone, String, null: false
field :island, IslandType, null: false, method: :island
field :archipel, ArchipelType, null: false, method: :archipel
field :created_at, String, null: false
field :updated_at, String, null: false
end
end
我不知道这个 'input' 东西是从哪里来的。
我在不知不觉中用一个使用 Relay 的配置初始化了我的项目。
通过在我的 **_schema.rb 文件中注释这段代码,它再次起作用了。
# Opt in to the new runtime (default in future graphql-ruby versions)
# use GraphQL::Execution::Interpreter
# use GraphQL::Analysis::AST
# Add built-in connections for pagination
# use GraphQL::Pagination::Connections
以及 base_mutation.rb 中的这些行并用这些替换。
# class BaseMutation < GraphQL::Schema::RelayClassicMutation
# argument_class Types::BaseArgument
# field_class Types::BaseField
# input_object_class Types::BaseInputObject
# object_class Types::BaseObject
# end
class BaseMutation < GraphQL::Schema::Mutation
null false
end
如果您对注释字段不感兴趣...我 运行 遇到了同样的错误。无论出于何种原因 input
是您将参数作为 hash/object.
使用本教程的示例:https://www.howtographql.com/graphql-ruby/3-mutations/
mutation {
createLink(input: {
url: "foo",
description:"bar"
}) {
url
description
}
}