Sha256: b4bc7aedbed71923e12907ff4df2aeb61fdeac197c684d2655085b27655e3416

Contents?: true

Size: 1.7 KB

Versions: 21

Compression:

Stored size: 1.7 KB

Contents

require_relative 'local_libs'

STRUCT_ID = "592642a4ae0c6a00236b110d" # mini test
# STRUCT_ID = "626745bcba616a001f7e5011" # wcc

api = Ecoportal::API::GraphQL.new

# DESIRED DESIGN: (to review: it might be that draft tree model already stores the commands?)
# tree = api.currentOrganization.LocationStructure(id: STRUCT_ID)
# node = tree.node["SYDNEY"]
# node.name = "Sydney City"
# tree.node["UPS"].move("AUCKLAND") # or tree.move("UPS", to: "AUCKLAND")
# tree.node["FFFF."].delete
# tree.node["UPS"].insert("CHILD", name: "Child").insert("GRAND CHILD", name: "Grand Child")
# tree.change_commands # => return Ecoportal::API::GraphQL::Input::ApplyCommands

INPUT = {
  change: {
    clientMutationId: "",
    id: STRUCT_ID,
    commands: [
      { update: { nodeId: "SYDNEY", name: "Sydney City" } },
      { move:   { nodeId: "UPS", parentId: "AUCKLAND" } },
      { archive: { nodeId: "FFFF." } },
      { insert: { parentId: "UPS", nodeId: "CHILD", name: "Child" } },
      { insert: { parentId: "CHILD", nodeId: "GRAND CHILD", name: "Grand Child" } }
    ]
  },
  revert: {
    clientMutationId: "",
    id: STRUCT_ID,
    commands: [
      { update: { nodeId: "SYDNEY", name: "Sydney" } },
      { move:   { nodeId: "UPS", parentId: "SUB'TAGs" } },
      { unarchive: { nodeId: "FFFF." } },
      { archive: { nodeId: "CHILD" } }
    ]
  }
}

operation = :change
response = api.locationStructure.applyCommands(input: INPUT[operation])

if response.success? && structure = response.structure
  puts "Applied '#{operation}' changes to '#{structure.name}' structure:"
  pp structure.treeify
end

puts "Some more feedback:"
#pp response.results.as_json
pp response.results.map(&:as_json)

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.2.1 tests/loc_structure_update.rb