Module: Binda::Api::Fields

Defined in:
lib/binda/api/fields.rb

Constant Summary collapse

SHARED_FIELDS =
Proc.new do |context|
  context.field :get_related_components, ::Binda::Api::Types::ComponentType.to_list_type do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.get_related_components(args[:slug])
    }
  end

  context.field :get_related_boards, ::Binda::Api::Types::BoardType.to_list_type do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.get_related_boards(args[:slug])
    }
  end

  context.field :get_string, ::Binda::Api::Types::TextType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      begin
        obj.get_string(args[:slug])
      rescue ArgumentError
        ""
      end
    }
  end

  context.field :get_text, ::Binda::Api::Types::TextType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      begin
        obj.get_text(args[:slug])
      rescue ArgumentError
        ""
      end
    }
  end 

  context.field :get_radio_choice, ::Binda::Api::Types::RadioType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.get_radio_choice(args[:slug])
    }
  end

  context.field :get_checkbox_choices, ::Binda::Api::Types::CheckboxType.to_list_type do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.get_checkbox_choices(args[:slug])
    }
  end

  context.field :get_selection_choice, ::Binda::Api::Types::SelectionType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.get_selection_choice(args[:slug])
    }
  end 

  context.field :get_image, ::Binda::Api::Types::ImageType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.images.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
    }
  end

  context.field :get_audio, ::Binda::Api::Types::AudioType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.audios.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
    }
  end

  context.field :get_video, ::Binda::Api::Types::VideoType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.videos.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
    }
  end 

  context.field :get_svg, ::Binda::Api::Types::SvgType do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.svgs.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
    }
  end

  context.field :repeaters, ::Binda::Api::Types::RepeaterType.to_list_type do
    argument :slug, !context.types.String

    resolve ->(obj, args, ctx) {
      obj.repeaters.order("binda_repeaters.position").select{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
    }
  end
end
RepeatersField =
GraphQL::Field.define do
  name 'repeaters'
  type Binda::Api::Types::RepeaterType.to_list_type

  argument :slug, !types.String
  argument :fieldable_slug, !types.String

  resolve(Binda::Api::Resolvers::RepeatersResolver.new)
end
ComponentsField =
GraphQL::Field.define do
  name 'components'

  argument :slug, types.String.to_list_type
  argument :structure_slug, types.String
  argument :publish_state, types.String

  type Binda::Api::Types::ComponentType.connection_type

  resolve(Binda::Api::Resolvers::ComponentsResolver.new)
end
StructuresField =
GraphQL::Field.define do
  name 'structures'
  type Binda::Api::Types::StructureType.connection_type

  resolve(Binda::Api::Resolvers::StructuresResolver.new)
end
BoardBySlugField =
GraphQL::Field.define do
  name 'boardBySlug'
  type Binda::Api::Types::BoardType

  argument :slug, !types.String

  resolve(Binda::Api::Resolvers::BoardBySlugResolver.new)
end
ComponentBySlugField =
GraphQL::Field.define do
  name 'componentBySlug'
  type Binda::Api::Types::ComponentType

  argument :slug, !types.String

  resolve(Binda::Api::Resolvers::ComponentBySlugResolver.new)
end
ComponentsByStructureField =
GraphQL::Field.define do
  name 'componentsByStructure'
  type Binda::Api::Types::ComponentType.connection_type

  argument :slug, !types.String
  argument :structure_slug, !types.String
  argument :publish_state, !types.String

  resolve(Binda::Api::Resolvers::ComponentsByStructureResolver.new)
end