Sha256: 06307e113ff0740a7ff720660f0859af2f31a2eb3cc18fe555c8edbfe10fee8a

Contents?: true

Size: 615 Bytes

Versions: 44

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true
GraphQL::STRING_TYPE = GraphQL::ScalarType.define do
  name "String"
  description "Represents textual data as UTF-8 character sequences. This type is most often used by GraphQL to represent free-form human-readable text."

  coerce_result ->(value, ctx) {
    begin
      str = value.to_s
      str.encoding == Encoding::UTF_8 ? str : str.encode(Encoding::UTF_8)
    rescue EncodingError
      err = GraphQL::StringEncodingError.new(str)
      ctx.schema.type_error(err, ctx)
    end
  }

  coerce_input ->(value, _ctx) { value.is_a?(String) ? value : nil }
  default_scalar true
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
graphql-1.8.2 lib/graphql/string_type.rb
graphql-1.8.1 lib/graphql/string_type.rb
graphql-1.8.0 lib/graphql/string_type.rb
graphql-1.8.0.pre11 lib/graphql/string_type.rb
graphql-1.8.0.pre10 lib/graphql/string_type.rb
graphql-1.7.14 lib/graphql/string_type.rb
graphql-1.8.0.pre9 lib/graphql/string_type.rb
graphql-1.8.0.pre8 lib/graphql/string_type.rb
graphql-1.7.13 lib/graphql/string_type.rb
graphql-1.8.0.pre7 lib/graphql/string_type.rb
graphql-1.7.12 lib/graphql/string_type.rb
graphql-1.7.11 lib/graphql/string_type.rb
graphql-1.7.10 lib/graphql/string_type.rb
graphql-1.8.0.pre6 lib/graphql/string_type.rb
graphql-1.8.0.pre5 lib/graphql/string_type.rb
graphql-1.7.9 lib/graphql/string_type.rb
graphql-1.8.0.pre4 lib/graphql/string_type.rb
graphql-1.8.0.pre3 lib/graphql/string_type.rb
graphql-1.7.8 lib/graphql/string_type.rb
graphql-1.8.0.pre2 lib/graphql/string_type.rb