shopify_graphql 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34fd94e0b5a246e1998c79a0e860c39e7f6fe842f2f8df3717955b9d4a7986b1
|
4
|
+
data.tar.gz: da89901175f71017f6ba9e0b94da554f760c061a26b87674d1c09726c947a1ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b489b44869cdd2a43fd2ab4682ed27766edf1aa998cd398c6c65e0a958be5612c2a2e3675202e6264011f9d3a38bd02e6fbd861f7d0e641321fbe4c84b30576
|
7
|
+
data.tar.gz: 2d85617836581b983afe601da73336a32536c5c198181de0c01ce2560d46164e708856de748597b0391d00dcc5144014141335d2c38ed3c6ba8cb61ce7869a77
|
data/README.md
CHANGED
@@ -737,6 +737,8 @@ ShopifyGraphql.handle_user_errors(response)
|
|
737
737
|
- `ShopifyGraphql::CreateRecurringSubscription`
|
738
738
|
- `ShopifyGraphql::CreateUsageSubscription`
|
739
739
|
- `ShopifyGraphql::GetAppSubscription`
|
740
|
+
- `ShopifyGraphql::UpsertPrivateMetafield`
|
741
|
+
- `ShopifyGraphql::DeletePrivateMetafield`
|
740
742
|
|
741
743
|
Built-in wrappers are located in [`app/graphql/shopify_graphql`](/app/graphql/shopify_graphql/) folder. You can use them directly in your apps or as an example to create your own wrappers.
|
742
744
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ShopifyGraphql
|
2
|
+
class DeletePrivateMetafield
|
3
|
+
include ShopifyGraphql::Mutation
|
4
|
+
|
5
|
+
MUTATION = <<~GRAPHQL
|
6
|
+
mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) {
|
7
|
+
privateMetafieldDelete(input: $input) {
|
8
|
+
deletedPrivateMetafieldId
|
9
|
+
userErrors {
|
10
|
+
field
|
11
|
+
message
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
GRAPHQL
|
16
|
+
|
17
|
+
def call(namespace:, key:, owner: nil)
|
18
|
+
input = {namespace: namespace, key: key}
|
19
|
+
input[:owner] = owner if owner
|
20
|
+
|
21
|
+
response = execute(MUTATION, input: input)
|
22
|
+
handle_user_errors(response.data.privateMetafieldDelete)
|
23
|
+
response.data = parse_data(response.data)
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_data(data)
|
30
|
+
id = data.privateMetafieldDelete.deletedPrivateMetafieldId
|
31
|
+
OpenStruct.new(
|
32
|
+
deleted_private_metafield_id: id
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ShopifyGraphql
|
2
|
+
class UpsertPrivateMetafield
|
3
|
+
include ShopifyGraphql::Mutation
|
4
|
+
|
5
|
+
MUTATION = <<~GRAPHQL
|
6
|
+
mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {
|
7
|
+
privateMetafieldUpsert(input: $input) {
|
8
|
+
privateMetafield {
|
9
|
+
id
|
10
|
+
namespace
|
11
|
+
key
|
12
|
+
value
|
13
|
+
valueType
|
14
|
+
}
|
15
|
+
userErrors {
|
16
|
+
field
|
17
|
+
message
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
GRAPHQL
|
22
|
+
|
23
|
+
def call(namespace:, key:, value:, owner: nil)
|
24
|
+
input = {namespace: namespace, key: key}
|
25
|
+
input[:owner] = owner if owner
|
26
|
+
|
27
|
+
case value
|
28
|
+
when Hash, Array
|
29
|
+
value = value.to_json
|
30
|
+
value_type = "JSON_STRING"
|
31
|
+
when Integer
|
32
|
+
value_type = "INTEGER"
|
33
|
+
else
|
34
|
+
value = value.to_s
|
35
|
+
value_type = "STRING"
|
36
|
+
end
|
37
|
+
input[:valueInput] = {value: value, valueType: value_type}
|
38
|
+
|
39
|
+
response = execute(MUTATION, input: input)
|
40
|
+
handle_user_errors(response.data.privateMetafieldUpsert)
|
41
|
+
response.data = parse_data(response.data)
|
42
|
+
response
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def parse_data(data)
|
48
|
+
metafield = data.privateMetafieldUpsert.privateMetafield
|
49
|
+
OpenStruct.new(
|
50
|
+
id: metafield.id,
|
51
|
+
namespace: metafield.namespace,
|
52
|
+
key: metafield.key,
|
53
|
+
value: metafield.value,
|
54
|
+
value_type: metafield.valueType
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -6,9 +6,13 @@ module ShopifyGraphql
|
|
6
6
|
|
7
7
|
def execute(query, **variables)
|
8
8
|
response = client.query(query: query, variables: variables)
|
9
|
-
|
9
|
+
Response.new(handle_response(response))
|
10
10
|
rescue ShopifyAPI::Errors::HttpResponseError => e
|
11
|
-
|
11
|
+
Response.new(handle_response(e.response))
|
12
|
+
rescue JSON::ParserError => e
|
13
|
+
raise ServerError.new(e, "Invalid JSON response")
|
14
|
+
rescue Errno::ECONNRESET, Errno::EPIPE, Net::ReadTimeout, Net::OpenTimeout, OpenSSL::SSL::SSLError => e
|
15
|
+
raise ServerError.new(e, "Network error")
|
12
16
|
end
|
13
17
|
|
14
18
|
def parsed_body(response)
|
@@ -65,6 +69,8 @@ module ShopifyGraphql
|
|
65
69
|
case error_code
|
66
70
|
when "THROTTLED"
|
67
71
|
raise TooManyRequests.new(response, error_message, code: error_code, doc: error_doc)
|
72
|
+
when "INTERNAL_SERVER_ERROR"
|
73
|
+
raise ServerError.new(response, error_message, code: error_code, doc: error_doc)
|
68
74
|
else
|
69
75
|
raise ConnectionError.new(response, error_message, code: error_code, doc: error_doc)
|
70
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Platonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,9 @@ files:
|
|
66
66
|
- app/graphql/shopify_graphql/cancel_subscription.rb
|
67
67
|
- app/graphql/shopify_graphql/create_recurring_subscription.rb
|
68
68
|
- app/graphql/shopify_graphql/create_usage_subscription.rb
|
69
|
+
- app/graphql/shopify_graphql/delete_private_metafield.rb
|
69
70
|
- app/graphql/shopify_graphql/get_app_subscription.rb
|
71
|
+
- app/graphql/shopify_graphql/upsert_private_metafield.rb
|
70
72
|
- config/routes.rb
|
71
73
|
- lib/shopify_graphql.rb
|
72
74
|
- lib/shopify_graphql/client.rb
|