Sha256: 440f1b67b70d03d816dbcfc9c82b68147bb889d620c330832cdf64dea3aac84e

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe GraphQL::Query::BaseExecution::ValueResolution do
  let(:debug) { false }
  let(:query_root) {
    day_of_week_enum = GraphQL::EnumType.define do
      name "DayOfWeek"
      value("MONDAY", value: 0)
      value("TUESDAY", value: 1)
      value("WEDNESDAY", value: 2)
      value("THURSDAY", value: 3)
      value("FRIDAY", value: 4)
      value("SATURDAY", value: 5)
      value("SUNDAY", value: 6)
    end
    GraphQL::ObjectType.define do
      name "Query"
      field :tomorrow, day_of_week_enum do
        argument :today, day_of_week_enum
        resolve ->(obj, args, ctx) { (args['today'] + 1) % 7 }
      end
    end
  }
  let(:schema) { GraphQL::Schema.new(query: query_root) }
  let(:result) { schema.execute(
    query_string,
    debug: debug,
  )}

  describe "enum resolution" do
    let(:query_string) { %|
      {
        tomorrow(today: FRIDAY)
      }
    |}

    it "coerces enum input to the value and result to the name" do
      expected = {
        "data" => {
          "tomorrow" => "SATURDAY"
        }
      }
      assert_equal(expected, result)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-0.10.9 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.8 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.7 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.6 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.5 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.4 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.3 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.2 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.1 spec/graphql/query/base_execution/value_resolution_spec.rb
graphql-0.10.0 spec/graphql/query/base_execution/value_resolution_spec.rb