-
I'm trying to write a Mutation using an input object. If i simply assign However, I would like to rename that object Here's the code. module Mutations::User
class Login < Mutations::BaseMutation
description "Login a user"
input_object_class Inputs::User::Login
field :token, String, null: true
field :user, Types::Models::UserType, null: true
def resolve(**arguments)
... module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
argument_class Types::BaseArgument
field_class Types::BaseField
input_object_class Inputs::BaseInputObject
object_class Types::BaseObject
... module Inputs::User
class Login < Inputs::BaseInputObject
description "Credentials necessary for user login"
graphql_name "LoginUserInput"
argument :login, String, required: true
argument :password, String, required: true
argument :remember_me, Boolean, required: false
end
end With a simple assignment of mutation userLogin {
userLogin(input: { login: "user_name", password: "123333" }) {
user {
id
name
email
}
token
}
} But if i assign the input object to module Mutations::User
class Login < Mutations::BaseMutation
description "Login a user"
argument :credentials, type: Inputs::User::Login, required: true
... I cannot access it in the query under mutation userLogin {
userLogin(credentials: { login: "user_name", password: "123333" }) {
user {
id
name
email
}
token
}
} I have to access it under mutation userLogin {
userLogin(input: { credentials: { login: "user_name", password: "123333" }}) {
user {
id
name
email
}
token
}
} So, what's going on here? Is there a way to give that input object a simple key In the analagous situation in a query resolver, i can assign the input type to an argument name and it is accessible under that name, it does not get nested under the generic For example this query resolver, the input object is assigned to the first argument, module Resolvers
class Observations < Resolvers::BaseResolver
type [Types::Models::ObservationType.connection_type], null: false
description "List or filter all observations"
argument :filter, type: Inputs::Observation::Filters, required: false
argument :order_by, type: Types::Enums::OrderBy, required: false
argument :order, type: Types::Enums::Order, required: false
def resolve(filter: nil, order_by: "WHEN", order: "DESC")
... module Resolvers
class BaseResolver < GraphQL::Schema::Resolver
end
end Here's the input object: module Inputs::Observation
class Filters < Inputs::BaseInputObject
description "Fields filtering an Observations query"
graphql_name "FilterObservationsInput"
argument :name_like, String, required: false
argument :location_like, String, required: false
argument :before, Boolean, required: false
argument :when, GraphQL::Types::ISO8601Date, required: false
... The query works with the assigned argument name, query getObservations {
observations(filter:{
nameLike:"Amanita"
locationLike:"Massachusetts"
} orderBy: WHEN, order: DESC) {
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
edges {
cursor
... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Doh! |
Beta Was this translation helpful? Give feedback.
Doh!
I was going to say "it's almost acting like a RelayClassicMutation" and then i noticed that it was in fact inheriting from that class.