Sha256: 1e6133a05855ed4de41f6609c30b9514b6fb7cbddc40304bcc2a731a8bc39ab9

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe GraphQL::Relay::Mutation do
  let(:query_string) {%|
    mutation addBagel($clientMutationId: String) {
      introduceShip(input: {shipName: "Bagel", factionId: "1", clientMutationId: $clientMutationId}) {
        clientMutationId
        shipEdge {
          node { name, id }
        }
        faction { name }
      }
    }
  |}
  let(:introspect) {%|
    {
      __schema {
        types { name, fields { name } }
      }
    }
  |}

  after do
    STAR_WARS_DATA["Ship"].delete("9")
    STAR_WARS_DATA["Faction"]["1"]["ships"].delete("9")
  end

  it "returns the result & clientMutationId" do
    result = star_wars_query(query_string, "clientMutationId" => "1234")
    expected = {"data" => {
      "introduceShip" => {
        "clientMutationId" => "1234",
        "shipEdge" => {
          "node" => {
            "name" => "Bagel",
            "id" => NodeIdentification.to_global_id("Ship", "9"),
          },
        },
        "faction" => {"name" => STAR_WARS_DATA["Faction"]["1"].name }
      }
    }}
    assert_equal(expected, result)
  end

  it "doesn't require a clientMutationId to perform mutations" do
    result = star_wars_query(query_string)
    new_ship_name = result["data"]["introduceShip"]["shipEdge"]["node"]["name"]
    assert_equal("Bagel", new_ship_name)
  end

  it "applies the description to the derived field" do
    assert_equal "Add a ship to this faction", IntroduceShipMutation.field.description
  end

  it "inserts itself into the derived objects' metadata" do
    assert_equal IntroduceShipMutation, IntroduceShipMutation.field.mutation
    assert_equal IntroduceShipMutation, IntroduceShipMutation.return_type.mutation
    assert_equal IntroduceShipMutation, IntroduceShipMutation.input_type.mutation
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
graphql-0.18.15 spec/graphql/relay/mutation_spec.rb
graphql-0.18.14 spec/graphql/relay/mutation_spec.rb
graphql-0.18.13 spec/graphql/relay/mutation_spec.rb
graphql-0.18.12 spec/graphql/relay/mutation_spec.rb
graphql-0.18.11 spec/graphql/relay/mutation_spec.rb
graphql-0.18.10 spec/graphql/relay/mutation_spec.rb