Sha256: 78a85e4eb14d57aa3651698a33dd0fcd7c0aa1b3045bee9adc228eaa80ed31fa
Contents?: true
Size: 1.63 KB
Versions: 15
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true module WCC::Contentful::Graphql::Types DateTimeType = GraphQL::ScalarType.define do name 'DateTime' coerce_result ->(value, _ctx) { Time.zone.parse(value) } end HashType = GraphQL::ScalarType.define do name 'Hash' coerce_result ->(value, _ctx) { return value if value.is_a? Array return value.to_h if value.respond_to?(:to_h) return JSON.parse(value) if value.is_a? String raise ArgumentError, "Cannot coerce value '#{value}' to a hash" } end CoordinatesType = GraphQL::ObjectType.define do name 'Coordinates' field :lat, !types.Float, hash_key: 'lat' field :lon, !types.Float, hash_key: 'lon' end StringQueryOperatorInput = GraphQL::InputObjectType.define do name 'StringQueryOperatorInput' argument :eq, types.String end QueryOperatorInput = ->(type) do map = { 'String' => StringQueryOperatorInput # 'Int' => # 'Boolean' => } map[type.unwrap.name] end FilterInputType = ->(schema_type) do GraphQL::InputObjectType.define do name "#{schema_type.name}FilterInput" schema_type.fields.each do |(name, field)| next unless input_type = QueryOperatorInput.call(field.type) argument name, input_type end end end BuildUnionType = ->(from_types, union_type_name) do possible_types = from_types.values.reject { |t| t.is_a? GraphQL::UnionType } GraphQL::UnionType.define do name union_type_name possible_types possible_types end end end
Version data entries
15 entries across 15 versions & 1 rubygems