Class: ShopifyGraphql::UpsertPrivateMetafield

Inherits:
Object
  • Object
show all
Includes:
Mutation
Defined in:
app/graphql/shopify_graphql/upsert_private_metafield.rb

Constant Summary collapse

MUTATION =
"mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n  privateMetafieldUpsert(input: $input) {\n    privateMetafield {\n      id\n      namespace\n      key\n      value\n      valueType\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}\n"

Instance Method Summary collapse

Methods included from Mutation

#client

Instance Method Details

#call(namespace:, key:, value:, owner: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/graphql/shopify_graphql/upsert_private_metafield.rb', line 23

def call(namespace:, key:, value:, owner: nil)
  input = {namespace: namespace, key: key}
  input[:owner] = owner if owner

  case value
  when Hash, Array
    value = value.to_json
    value_type = "JSON_STRING"
  when Integer
    value_type = "INTEGER"
  else
    value = value.to_s
    value_type = "STRING"
  end
  input[:valueInput] = {value: value, valueType: value_type}

  response = execute(MUTATION, input: input)
  handle_user_errors(response.data.privateMetafieldUpsert)
  response.data = parse_data(response.data)
  response
end