Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments using loads don't get loaded in mutations unless in a subtype #49

Open
alexanderdavide opened this issue Dec 27, 2020 · 0 comments

Comments

@alexanderdavide
Copy link

alexanderdavide commented Dec 27, 2020

Apparent bug

It seems like arguments of mutations that use loads to automatically load the types from the database don't get loaded unless they are nested in another type. With queries I have not experienced any issues.

Environment

rails: 6.0.3
graphql_ruby: 1.11.6
graphql_guard: 2.0

Description

This query works fine. The facility entity is present in args[facility] in the GuardPolicy. args is a hash.

field :facility, Types::Facility::FacilityType, 'Returns a certain Facility',
                        null: false, authenticate: false do
        argument :facility_id, GraphQL::Types::ID, required: true, loads: Types::Facility::FacilityType
        argument :locale, String, required: true
      end

def facility(facility:, locale:)
  facility
end

This mutation does not work. There is a args[exhibitor] key ('_id' is stripped) but it contains the bare exhibitor_id. In comparison to the query, args is of type class.

class UpdateExhibitor < Mutations::BaseMutation
  null false
  
  argument :locale, String, required: true
  argument :exhibitor_id, ID, required: true, loads: Types::Exhibitor::ExhibitorType
  argument :data, Types::Exhibitor::ExhibitorUpdateInput, required: true
  
  type Types::Exhibitor::ExhibitorType
  
  def resolve(locale:, exhibitor:, data:)
    EntityInteraction.update_entity(exhibitor, data)
  end
end

This mutation does work. It contains the loaded argument in a 'nested' type. The exhibition entity is available in args[:data][:exhibition]:

class CreateEvent < Mutations::BaseMutation
  null false

  argument :locale, String, required: true
  argument :data, Types::Shared::AssociatedWithExhibitionCreateInput, required: true

  type Types::Event::EventType

  def resolve(locale:, data:)
    EntityInteraction.create_entity(::Event, data)
  end
end
class AssociatedWithExhibitionCreateInput < BaseCreateInput
  description 'Attributes for create action of entities associated with exhibition'
  argument :exhibition_id, ID, required: true, loads: Exhibition::ExhibitionType
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant