Class: DiscoApp::GraphqlClient
- Inherits:
-
Object
- Object
- DiscoApp::GraphqlClient
- Defined in:
- app/clients/disco_app/graphql_client.rb
Instance Method Summary collapse
-
#create_flow_trigger(title, resource_name, resource_url, properties) ⇒ Object
Fire a Shopify Flow Trigger.
-
#initialize(shop) ⇒ GraphqlClient
constructor
A new instance of GraphqlClient.
Constructor Details
#initialize(shop) ⇒ GraphqlClient
Returns a new instance of GraphqlClient.
25 26 27 |
# File 'app/clients/disco_app/graphql_client.rb', line 25 def initialize(shop) @shop = shop end |
Instance Method Details
#create_flow_trigger(title, resource_name, resource_url, properties) ⇒ Object
Fire a Shopify Flow Trigger. Returns a tuple Array representing errors.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/clients/disco_app/graphql_client.rb', line 32 def create_flow_trigger(title, resource_name, resource_url, properties) body = { trigger_title: title, resources: [ { name: resource_name, url: resource_url } ], properties: properties } # The double .to_json.to_json below looks odd but is required to properly escape the JSON hash # when inserting it into the GraphQL mutation call. response = execute(%( mutation { flowTriggerReceive(body: #{body.to_json.to_json}) { userErrors { field, message } } } )) errors = response.dig(:data, :flowTriggerReceive, :userErrors) [errors.empty?, errors] end |