Sha256: 2920d2617bdb89da2abc3eba117264e3ff73e582996e7a4b282bebbc62d1503a

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

require "spec_helper"

describe GraphQL::Query::SerialExecution::ValueResolution do
  let(:schema) {
    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

    interface = GraphQL::InterfaceType.define do
      name "SomeInterface"
      field :someField, !types.Int
    end

    query_root = 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
      field :misbehavedInterface, interface do
        resolve ->(obj, args, ctx) { Object.new }
      end
    end

    GraphQL::Schema.define do
      query(query_root)
      resolve_type -> (obj, ctx) { nil }
    end
  }

  let(:result) { schema.execute(
    query_string,
  )}

  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

  describe "interface type resolution" do
    let(:query_string) { %|
      {
        misbehavedInterface { someField }
      }
    |}

    it "raises an error if it cannot resolve the type of an interface" do
      assert_raises(GraphQL::ObjectType::UnresolvedTypeError) { result }
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql-0.19.0 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.15 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.14 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.13 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.12 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.11 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.10 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.9 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.8 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.7 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.6 spec/graphql/query/serial_execution/value_resolution_spec.rb
graphql-0.18.5 spec/graphql/query/serial_execution/value_resolution_spec.rb