Sha256: 971d5a3c02b4565923359f3c1ad2cbf8481ad9c7f220a643f3410fecc05bb3ca

Contents?: true

Size: 1.56 KB

Versions: 61

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Define::AssignArgument do
  it "it accepts default_value" do
    arg = define_argument(:a, GraphQL::STRING_TYPE, default_value: 'Default')

    assert_equal "Default", arg.default_value
    assert arg.default_value?
  end

  it "default_value is optional" do
    arg = define_argument(:a, GraphQL::STRING_TYPE)

    assert arg.default_value.nil?
    assert !arg.default_value?
  end

  it "default_value can be explicitly set to nil" do
    arg = define_argument(:a, GraphQL::STRING_TYPE, default_value: nil)

    assert arg.default_value.nil?
    assert arg.default_value?
  end

  it "passing unknown keyword arguments will raise" do
    err = assert_raises GraphQL::Define::NoDefinitionError do
      define_argument(:a, GraphQL::STRING_TYPE, blah: nil)
    end

    assert_equal "GraphQL::Argument can't define 'blah'", err.message

    err = assert_raises GraphQL::Define::NoDefinitionError do
      define_argument(:a, GraphQL::STRING_TYPE, blah: nil, blah2: nil)
    end

    assert_equal "GraphQL::Argument can't define 'blah'", err.message
  end

  it "accepts an existing argument" do
    existing = GraphQL::Argument.define do
      name "bar"
      type GraphQL::STRING_TYPE
    end

    arg = define_argument(:foo, existing)

    assert_equal "foo", arg.name
    assert_equal GraphQL::STRING_TYPE, arg.type
  end

  def define_argument(*args)
    type = GraphQL::ObjectType.define do
      field :a, types.String do
        argument(*args)
      end
    end

    type.fields['a'].arguments[args.first.to_s]
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
graphql-1.8.13 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.12 spec/graphql/define/assign_argument_spec.rb
graphql-1.9.0.pre1 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.11 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.10 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.9 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.8 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.7 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.6 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.5 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.4 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.3 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.2 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.1 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.0 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.0.pre11 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.0.pre10 spec/graphql/define/assign_argument_spec.rb
graphql-1.7.14 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.0.pre9 spec/graphql/define/assign_argument_spec.rb
graphql-1.8.0.pre8 spec/graphql/define/assign_argument_spec.rb