Class: Rails::GraphQL::Type::Scalar::BinaryScalar

Inherits:
Rails::GraphQL::Type::Scalar show all
Defined in:
lib/rails/graphql/type/scalar/binary_scalar.rb

Overview

Binary basically allows binary data to be shared using Base64 strings, ensuring the UTF-8 encoding and performing the necessary conversion.

It also rely on ActiveModel so it can easily share the same Data object.

Constant Summary

Constants inherited from Rails::GraphQL::Type

KINDS

Class Method Summary collapse

Methods inherited from Rails::GraphQL::Type::Scalar

inspect, to_json, valid_input?, valid_output?

Methods inherited from Rails::GraphQL::Type

=~, base_type, create!, decorate, find_by_gid, gid_base_class, input_type?, kind, kind_enum, leaf_type?, operational?, output_type?, to_gql_backtrace

Methods included from Helpers::WithDirectives

#all_directive_events, #all_directive_listeners, #directive_events?, #directive_listeners?, extended, included, #initialize_copy, #use, #using?, #validate!

Methods included from Helpers::WithGlobalID

#to_gid_param, #to_global_id

Methods included from Helpers::Registerable

#aliases, extended, #inherited, #register!, #registered?

Class Method Details

.as_json(value) ⇒ Object



21
22
23
# File 'lib/rails/graphql/type/scalar/binary_scalar.rb', line 21

def as_json(value)
  Base64.encode64(value.to_s).chomp
end

.deserialize(value) ⇒ Object



25
26
27
# File 'lib/rails/graphql/type/scalar/binary_scalar.rb', line 25

def deserialize(value)
  ActiveModel::Type::Binary::Data.new(Base64.decode64(value))
end