rmosolgo/graphql-ruby

graphql_name does not take effect

xiaoduwuer opened this issue · 2 comments

I have upgraded the version of GraphQL to the latest version, and in Mutations::Distributor::Create, I have set the graphql_name to 'DistributorCreate'. I expect the name of the return type to be DistributorCreatePayload. However, in the generated schema.graphql file, the return type is CreatePayload.

graphql (2.3.9)
  base64
graphql-batch (0.6.0)
  graphql (>= 1.12.18, < 3)
  promise.rb (~> 0.7.2)

an important line of code in Mutations::Distributor::Base

included do
   field :errors, Types::ValidationErrorsType, null: true
end
Mutation GraphQL FULL
class XiaoduwuSchema < GraphQL::Schema
  mutation(Types::MutationType)
end

module Types
  class MutationType < GraphQL::Schema::Object
    field :distributor_create, mutation: Mutations::Distributor::Create
  end
end

module Mutations
  module Distributor
    class Create < GraphQL::Schema::RelayClassicMutation
      include Distributor::Base

      graphql_name 'DistributorCreate'

    end
  end
end

module Mutations
  module Distributor
    module Base
      extend ActiveSupport::Concern

      included do
        field :errors, Types::ValidationErrorsType, null: true
      end
    end
  end
end


module Types
  class ValidationErrorsType < GraphQL::Schema::Object
    field :details, String, null: false
    field :full_messages, [String], null: false

    def details
      object.details.to_json
    end
  end
end
JSON.parse XiaoduwuSchema.to_definition
Autogenerated return type of Create.
"""
type CreatePayload {
  """
  A unique identifier for the client performing the mutation.
  """
  clientMutationId: String
  errors: ValidationErrors
}

"""
Autogenerated input type of DistributorCreate
"""
input DistributorCreateInput {
  """
  A unique identifier for the client performing the mutation.
  """
  clientMutationId: String
}

type Mutation {
  distributorCreate(
    """
    Parameters for DistributorCreate
    """
    input: DistributorCreateInput!
  ): CreatePayload
}

type ValidationErrors {
  details: String!
  fullMessages: [String!]!
}

#3919
Having graphql_name called after any arguments are defined can cause naming issues. So just standardize on putting it at the top.

Ahh, yes! Defining an argument is what causes the input type to be defined, and the input type takes its name from the mutation at that moment. I'm glad you got to the bottom of it -- and thanks for sharing your solution 👍