solidus_graphql_api 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +18 -2
  3. data/.github/dependabot.yml +23 -0
  4. data/.github/stale.yml +3 -3
  5. data/.github_changelog_generator +2 -0
  6. data/.rubocop.yml +7 -4
  7. data/CHANGELOG.md +170 -0
  8. data/Gemfile +0 -5
  9. data/LICENSE +1 -1
  10. data/README.md +25 -9
  11. data/Rakefile +21 -7
  12. data/app/assets/javascripts/spree/backend/solidus_graphql_api.js +2 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_graphql_api.js +2 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_graphql_api.css +4 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_graphql_api.css +4 -0
  16. data/app/controllers/spree/graphql_controller.rb +2 -0
  17. data/bin/console +2 -2
  18. data/bin/rails +0 -2
  19. data/bin/rails-engine +0 -3
  20. data/bin/rails-sandbox +1 -3
  21. data/bin/rake +0 -1
  22. data/bin/sandbox +3 -1
  23. data/docs/assets/images/graphiql-headers.png +0 -0
  24. data/docs/assets/images/graphiql-variables.png +0 -0
  25. data/docs/assets/images/graphiql.png +0 -0
  26. data/docs/assets/images/menu.png +0 -0
  27. data/docs/assets/images/navbar.png +0 -0
  28. data/docs/assets/style.css +1115 -0
  29. data/docs/assets/webfonts/2C4B9D_B_0.eot +0 -0
  30. data/docs/assets/webfonts/2C4B9D_B_0.ttf +0 -0
  31. data/docs/assets/webfonts/2C4B9D_B_0.woff +0 -0
  32. data/docs/assets/webfonts/2C4B9D_B_0.woff2 +0 -0
  33. data/docs/assets/webfonts/2C4B9D_C_0.eot +0 -0
  34. data/docs/assets/webfonts/2C4B9D_C_0.ttf +0 -0
  35. data/docs/assets/webfonts/2C4B9D_C_0.woff +0 -0
  36. data/docs/assets/webfonts/2C4B9D_C_0.woff2 +0 -0
  37. data/docs/assets/webfonts/2C4B9D_D_0.eot +0 -0
  38. data/docs/assets/webfonts/2C4B9D_D_0.ttf +0 -0
  39. data/docs/assets/webfonts/2C4B9D_D_0.woff +0 -0
  40. data/docs/assets/webfonts/2C4B9D_D_0.woff2 +0 -0
  41. data/docs/assets/webfonts/2C4B9D_E_0.eot +0 -0
  42. data/docs/assets/webfonts/2C4B9D_E_0.ttf +0 -0
  43. data/docs/assets/webfonts/2C4B9D_E_0.woff +0 -0
  44. data/docs/assets/webfonts/2C4B9D_E_0.woff2 +0 -0
  45. data/docs/directive/deprecated/index.html +1142 -0
  46. data/docs/directive/include/index.html +1141 -0
  47. data/docs/directive/index.html +1113 -0
  48. data/docs/directive/skip/index.html +1141 -0
  49. data/docs/enum/__directivelocation/index.html +1204 -0
  50. data/docs/enum/__typekind/index.html +1154 -0
  51. data/docs/enum/addresstypeinput/index.html +1121 -0
  52. data/docs/enum/index.html +1113 -0
  53. data/docs/index.html +1122 -0
  54. data/docs/input_object/addaddressestocheckoutinput/index.html +1135 -0
  55. data/docs/input_object/addpaymenttocheckoutinput/index.html +1135 -0
  56. data/docs/input_object/addressinput/index.html +1169 -0
  57. data/docs/input_object/addtocartinput/index.html +1130 -0
  58. data/docs/input_object/advancecheckoutinput/index.html +1120 -0
  59. data/docs/input_object/applycouponcodeinput/index.html +1125 -0
  60. data/docs/input_object/completecheckoutinput/index.html +1120 -0
  61. data/docs/input_object/createorderinput/index.html +1120 -0
  62. data/docs/input_object/emptycartinput/index.html +1120 -0
  63. data/docs/input_object/index.html +1113 -0
  64. data/docs/input_object/markdefaultshipaddressinput/index.html +1125 -0
  65. data/docs/input_object/nextcheckoutstateinput/index.html +1120 -0
  66. data/docs/input_object/productsqueryinput/index.html +1132 -0
  67. data/docs/input_object/removefromaddressbookinput/index.html +1125 -0
  68. data/docs/input_object/removefromcartinput/index.html +1125 -0
  69. data/docs/input_object/saveinaddressbookinput/index.html +1135 -0
  70. data/docs/input_object/selectshippingrateinput/index.html +1125 -0
  71. data/docs/input_object/setorderemailinput/index.html +1125 -0
  72. data/docs/input_object/updatecartquantityinput/index.html +1130 -0
  73. data/docs/interface/adjustment/index.html +1145 -0
  74. data/docs/interface/index.html +1113 -0
  75. data/docs/interface/node/index.html +1151 -0
  76. data/docs/interface/paymentsource/index.html +1134 -0
  77. data/docs/mutation/addaddressestocheckout/index.html +1137 -0
  78. data/docs/mutation/addpaymenttocheckout/index.html +1137 -0
  79. data/docs/mutation/addtocart/index.html +1137 -0
  80. data/docs/mutation/advancecheckout/index.html +1137 -0
  81. data/docs/mutation/applycouponcode/index.html +1137 -0
  82. data/docs/mutation/completecheckout/index.html +1137 -0
  83. data/docs/mutation/createorder/index.html +1137 -0
  84. data/docs/mutation/emptycart/index.html +1137 -0
  85. data/docs/mutation/markdefaultshipaddress/index.html +1132 -0
  86. data/docs/mutation/nextcheckoutstate/index.html +1137 -0
  87. data/docs/mutation/removefromaddressbook/index.html +1132 -0
  88. data/docs/mutation/removefromcart/index.html +1137 -0
  89. data/docs/mutation/saveinaddressbook/index.html +1137 -0
  90. data/docs/mutation/selectshippingrate/index.html +1137 -0
  91. data/docs/mutation/setorderemail/index.html +1137 -0
  92. data/docs/mutation/updatecartquantity/index.html +1137 -0
  93. data/docs/object/__directive/index.html +1182 -0
  94. data/docs/object/__enumvalue/index.html +1134 -0
  95. data/docs/object/__field/index.html +1164 -0
  96. data/docs/object/__inputvalue/index.html +1145 -0
  97. data/docs/object/__schema/index.html +1144 -0
  98. data/docs/object/__type/index.html +1220 -0
  99. data/docs/object/addaddressestocheckoutpayload/index.html +1130 -0
  100. data/docs/object/addpaymenttocheckoutpayload/index.html +1130 -0
  101. data/docs/object/address/index.html +1189 -0
  102. data/docs/object/addressconnection/index.html +1132 -0
  103. data/docs/object/addressedge/index.html +1126 -0
  104. data/docs/object/addtocartpayload/index.html +1130 -0
  105. data/docs/object/adjustmentconnection/index.html +1132 -0
  106. data/docs/object/adjustmentedge/index.html +1126 -0
  107. data/docs/object/advancecheckoutpayload/index.html +1130 -0
  108. data/docs/object/applycouponcodepayload/index.html +1130 -0
  109. data/docs/object/completecheckoutpayload/index.html +1130 -0
  110. data/docs/object/country/index.html +1218 -0
  111. data/docs/object/countryconnection/index.html +1132 -0
  112. data/docs/object/countryedge/index.html +1126 -0
  113. data/docs/object/createorderpayload/index.html +1130 -0
  114. data/docs/object/creditcard/index.html +1170 -0
  115. data/docs/object/currency/index.html +1144 -0
  116. data/docs/object/currencyconnection/index.html +1132 -0
  117. data/docs/object/currencyedge/index.html +1126 -0
  118. data/docs/object/emptycartpayload/index.html +1130 -0
  119. data/docs/object/image/index.html +1169 -0
  120. data/docs/object/imageconnection/index.html +1132 -0
  121. data/docs/object/imageedge/index.html +1126 -0
  122. data/docs/object/index.html +1113 -0
  123. data/docs/object/lineitem/index.html +1184 -0
  124. data/docs/object/lineitemconnection/index.html +1132 -0
  125. data/docs/object/lineitemedge/index.html +1126 -0
  126. data/docs/object/manifestitem/index.html +1124 -0
  127. data/docs/object/markdefaultshipaddresspayload/index.html +1125 -0
  128. data/docs/object/nextcheckoutstatepayload/index.html +1130 -0
  129. data/docs/object/optiontype/index.html +1203 -0
  130. data/docs/object/optiontypeconnection/index.html +1132 -0
  131. data/docs/object/optiontypeedge/index.html +1126 -0
  132. data/docs/object/optionvalue/index.html +1154 -0
  133. data/docs/object/optionvalueconnection/index.html +1132 -0
  134. data/docs/object/optionvalueedge/index.html +1126 -0
  135. data/docs/object/order/index.html +1412 -0
  136. data/docs/object/orderconnection/index.html +1132 -0
  137. data/docs/object/orderedge/index.html +1126 -0
  138. data/docs/object/pageinfo/index.html +1138 -0
  139. data/docs/object/payment/index.html +1149 -0
  140. data/docs/object/paymentmethod/index.html +1149 -0
  141. data/docs/object/price/index.html +1159 -0
  142. data/docs/object/priceconnection/index.html +1132 -0
  143. data/docs/object/priceedge/index.html +1126 -0
  144. data/docs/object/product/index.html +1327 -0
  145. data/docs/object/productconnection/index.html +1132 -0
  146. data/docs/object/productedge/index.html +1126 -0
  147. data/docs/object/productproperty/index.html +1149 -0
  148. data/docs/object/productpropertyconnection/index.html +1132 -0
  149. data/docs/object/productpropertyedge/index.html +1126 -0
  150. data/docs/object/promotionadjustment/index.html +1155 -0
  151. data/docs/object/property/index.html +1144 -0
  152. data/docs/object/removefromaddressbookpayload/index.html +1125 -0
  153. data/docs/object/removefromcartpayload/index.html +1130 -0
  154. data/docs/object/saveinaddressbookpayload/index.html +1130 -0
  155. data/docs/object/selectshippingratepayload/index.html +1130 -0
  156. data/docs/object/setorderemailpayload/index.html +1130 -0
  157. data/docs/object/shipment/index.html +1218 -0
  158. data/docs/object/shipmentconnection/index.html +1132 -0
  159. data/docs/object/shipmentedge/index.html +1126 -0
  160. data/docs/object/shippingmethod/index.html +1174 -0
  161. data/docs/object/shippingrate/index.html +1154 -0
  162. data/docs/object/shippingrateconnection/index.html +1132 -0
  163. data/docs/object/shippingrateedge/index.html +1126 -0
  164. data/docs/object/state/index.html +1144 -0
  165. data/docs/object/stateconnection/index.html +1132 -0
  166. data/docs/object/stateedge/index.html +1126 -0
  167. data/docs/object/store/index.html +1238 -0
  168. data/docs/object/taxadjustment/index.html +1150 -0
  169. data/docs/object/taxon/index.html +1228 -0
  170. data/docs/object/taxonconnection/index.html +1132 -0
  171. data/docs/object/taxonedge/index.html +1126 -0
  172. data/docs/object/taxonomy/index.html +1198 -0
  173. data/docs/object/taxonomyconnection/index.html +1132 -0
  174. data/docs/object/taxonomyedge/index.html +1126 -0
  175. data/docs/object/updatecartquantitypayload/index.html +1130 -0
  176. data/docs/object/user/index.html +1280 -0
  177. data/docs/object/usererror/index.html +1126 -0
  178. data/docs/object/variant/index.html +1332 -0
  179. data/docs/object/variantconnection/index.html +1132 -0
  180. data/docs/object/variantedge/index.html +1126 -0
  181. data/docs/object/walletpaymentsource/index.html +1144 -0
  182. data/docs/object/walletpaymentsourceconnection/index.html +1132 -0
  183. data/docs/object/walletpaymentsourceedge/index.html +1126 -0
  184. data/docs/operation/mutation/index.html +1114 -0
  185. data/docs/operation/query/index.html +1431 -0
  186. data/docs/scalar/boolean/index.html +1112 -0
  187. data/docs/scalar/float/index.html +1112 -0
  188. data/docs/scalar/id/index.html +1112 -0
  189. data/docs/scalar/index.html +1113 -0
  190. data/docs/scalar/int/index.html +1112 -0
  191. data/docs/scalar/iso8601datetime/index.html +1112 -0
  192. data/docs/scalar/json/index.html +1112 -0
  193. data/docs/scalar/string/index.html +1112 -0
  194. data/docs/union/index.html +1113 -0
  195. data/lib/generators/solidus_graphql_api/install/install_generator.rb +19 -0
  196. data/lib/generators/solidus_graphql_api/install/templates/initializer.rb +6 -0
  197. data/lib/graphql_docs/landing_pages/index.md +16 -0
  198. data/lib/solidus_graphql_api/batch_loader/has_many_through.rb +1 -0
  199. data/lib/solidus_graphql_api/configuration.rb +12 -8
  200. data/lib/solidus_graphql_api/context.rb +7 -1
  201. data/lib/solidus_graphql_api/engine.rb +2 -2
  202. data/lib/solidus_graphql_api/mutations/base_mutation.rb +3 -3
  203. data/lib/solidus_graphql_api/mutations/checkout/add_payment_to_checkout.rb +1 -1
  204. data/lib/solidus_graphql_api/mutations/user/{mark_default_address.rb → mark_default_ship_address.rb} +2 -2
  205. data/lib/solidus_graphql_api/mutations/user/save_in_address_book.rb +8 -2
  206. data/lib/solidus_graphql_api/queries/option_value/option_type_query.rb +19 -0
  207. data/lib/solidus_graphql_api/queries/shipping_rate/shipping_method_query.rb +19 -0
  208. data/lib/solidus_graphql_api/queries/variant/default_price_query.rb +1 -1
  209. data/lib/solidus_graphql_api/{factories → testing_support/factories}/address_factory.rb +1 -2
  210. data/lib/solidus_graphql_api/{factories → testing_support/factories}/country_factory.rb +0 -0
  211. data/lib/solidus_graphql_api/{factories → testing_support/factories}/store_factory.rb +0 -0
  212. data/lib/solidus_graphql_api/{factories → testing_support/factories}/taxonomy_factory.rb +10 -0
  213. data/lib/solidus_graphql_api/testing_support/factories.rb +9 -0
  214. data/lib/solidus_graphql_api/types/address.rb +1 -2
  215. data/lib/solidus_graphql_api/types/base/relay_node.rb +1 -1
  216. data/lib/solidus_graphql_api/types/input_objects/address_input.rb +1 -2
  217. data/lib/solidus_graphql_api/types/json.rb +6 -3
  218. data/lib/solidus_graphql_api/types/mutation.rb +1 -1
  219. data/lib/solidus_graphql_api/types/option_value.rb +5 -0
  220. data/lib/solidus_graphql_api/types/query.rb +2 -2
  221. data/lib/solidus_graphql_api/types/shipping_method.rb +20 -0
  222. data/lib/solidus_graphql_api/types/shipping_rate.rb +5 -0
  223. data/lib/solidus_graphql_api/types/user.rb +1 -1
  224. data/lib/solidus_graphql_api/version.rb +1 -1
  225. data/lib/solidus_graphql_api.rb +0 -3
  226. data/schema.graphql +128 -26
  227. data/solidus_graphql_api.gemspec +9 -7
  228. data/spec/integration/mutations/checkout/add_addresses_to_checkout_spec.rb +12 -18
  229. data/spec/integration/mutations/checkout/apply_coupon_code_spec.rb +3 -1
  230. data/spec/integration/mutations/{mark_default_address_spec.rb → mark_default_ship_address_spec.rb} +5 -5
  231. data/spec/integration/mutations/remove_from_address_book_spec.rb +4 -4
  232. data/spec/integration/mutations/save_in_address_book_spec.rb +25 -12
  233. data/spec/integration/queries/completed_orders_spec.rb +19 -15
  234. data/spec/integration/queries/current_order_spec.rb +4 -1
  235. data/spec/integration/queries/current_store_spec.rb +1 -1
  236. data/spec/integration/queries/products_spec.rb +4 -1
  237. data/spec/integration/queries/taxonomies_spec.rb +9 -4
  238. data/spec/integration/types/json_spec.rb +17 -0
  239. data/spec/lib/solidus_graphql_api/batch_loader/has_many_through_spec.rb +27 -15
  240. data/spec/lib/solidus_graphql_api/context_spec.rb +119 -6
  241. data/spec/lib/solidus_graphql_api/queries/option_value/option_type_query_spec.rb +10 -0
  242. data/spec/lib/solidus_graphql_api/queries/shipping_rate/shipping_method_query_spec.rb +11 -0
  243. data/spec/lib/solidus_graphql_api/queries/variant/default_price_query_spec.rb +1 -1
  244. data/spec/lib/solidus_graphql_api/types/base/object_spec.rb +5 -1
  245. data/spec/lib/solidus_graphql_api/types/json_spec.rb +2 -1
  246. data/spec/lib/solidus_graphql_api/types/option_value_spec.rb +22 -0
  247. data/spec/lib/solidus_graphql_api/types/product_spec.rb +3 -1
  248. data/spec/lib/solidus_graphql_api/types/query_spec.rb +3 -1
  249. data/spec/lib/solidus_graphql_api/types/shipping_rate_spec.rb +22 -0
  250. data/spec/requests/spree/graphql_controller_spec.rb +15 -2
  251. data/spec/spec_helper.rb +15 -9
  252. data/spec/support/expected_schema.graphql +128 -26
  253. data/spec/support/graphql/mutations/add_addresses_to_checkout.gql +2 -2
  254. data/spec/support/graphql/mutations/mark_default_ship_address.gql +9 -0
  255. data/spec/support/graphql/mutations/remove_from_address_book.gql +1 -1
  256. data/spec/support/graphql/mutations/save_in_address_book.gql +6 -5
  257. data/spec/support/graphql/queries/completed_orders/billing_address.gql +1 -2
  258. data/spec/support/graphql/queries/completed_orders/shipping_address.gql +1 -2
  259. data/spec/support/graphql/queries/current_user.gql +6 -11
  260. data/spec/support/graphql/responses/completed_orders/billing_address.json.erb +2 -4
  261. data/spec/support/graphql/responses/completed_orders/shipping_address.json.erb +2 -4
  262. data/spec/support/graphql/responses/current_store.json.erb +1 -1
  263. data/spec/support/graphql/responses/current_user.json.erb +7 -13
  264. data/spec/support/graphql/responses/taxonomies.json.erb +7 -7
  265. metadata +252 -37
  266. data/lib/solidus_graphql_api/factories.rb +0 -11
  267. data/spec/support/graphql/mutations/mark_default_address.gql +0 -9
@@ -3,6 +3,25 @@
3
3
  module SolidusGraphqlApi
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
+ class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def copy_initializer
10
+ template 'initializer.rb', 'config/initializers/solidus_graphql_api.rb'
11
+ end
12
+
13
+ def add_migrations
14
+ run 'bin/rails railties:install:migrations FROM=solidus_graphql_api'
15
+ end
16
+
17
+ def run_migrations
18
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
19
+ if run_migrations
20
+ run 'bin/rails db:migrate'
21
+ else
22
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
23
+ end
24
+ end
6
25
  end
7
26
  end
8
27
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusGraphqlApi.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ title: Solidus GraphQL documentation
3
+ ---
4
+
5
+ # Solidus GraphQL API
6
+
7
+ This is the GraphQL documentation for the [Solidus](https://github.com/solidusio/solidus) ecommerce platform.
8
+
9
+ ## Quick Reference
10
+
11
+ - Solidus's GraphQL API endpoint is located at `/graphql`.
12
+ - Check out GraphQL's [official documentation](https://graphql.org/)
13
+
14
+ ## Need help?
15
+
16
+ Join the [SolidusSlack#support-channel](http://slack.solidus.io/) and start a conversation.
@@ -24,6 +24,7 @@ module SolidusGraphqlApi
24
24
  base_relation
25
25
  .joins(through_reflection.name)
26
26
  .where("#{through_reflection.table_name}.#{through_reflection.foreign_key}" => object_ids)
27
+ .distinct
27
28
  end
28
29
 
29
30
  def group_records_by_parent(records)
@@ -1,14 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusGraphqlApi
4
- def self.configure
5
- yield configuration
6
- end
7
-
8
- def self.configuration
9
- @configuration ||= Configuration.new
10
- end
11
-
12
4
  class Configuration
13
5
  attr_accessor :payment_sources
14
6
 
@@ -16,4 +8,16 @@ module SolidusGraphqlApi
16
8
  @payment_sources = ['SolidusGraphqlApi::Types::CreditCard']
17
9
  end
18
10
  end
11
+
12
+ class << self
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ alias config configuration
18
+
19
+ def configure
20
+ yield configuration
21
+ end
22
+ end
19
23
  end
@@ -22,7 +22,11 @@ module SolidusGraphqlApi
22
22
  end
23
23
 
24
24
  def current_user
25
- @current_user ||= Spree.user_class.find_by(spree_api_key: bearer_token)
25
+ @current_user ||= begin
26
+ return nil unless bearer_token&.present?
27
+
28
+ Spree.user_class.find_by(spree_api_key: bearer_token)
29
+ end
26
30
  end
27
31
 
28
32
  def current_ability
@@ -60,6 +64,8 @@ module SolidusGraphqlApi
60
64
  end
61
65
 
62
66
  def current_order_by_guest_token
67
+ return if order_token.blank?
68
+
63
69
  incomplete_orders = Spree::Order.incomplete
64
70
  incomplete_orders = incomplete_orders.where(store: current_store) if current_store
65
71
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/core'
4
- require 'solidus_graphql_api'
3
+ require 'solidus_core'
4
+ require 'solidus_support'
5
5
 
6
6
  module SolidusGraphqlApi
7
7
  class Engine < Rails::Engine
@@ -33,10 +33,10 @@ module SolidusGraphqlApi
33
33
  def user_errors(*path, errors)
34
34
  return [] if errors.empty?
35
35
 
36
- errors.map do |attribute, message|
36
+ errors.map do |error|
37
37
  {
38
- path: ["input", *path].concat(attribute.to_s.camelize(:lower).split('.')),
39
- message: message,
38
+ path: ["input", *path].concat(error.attribute.to_s.camelize(:lower).split('.')),
39
+ message: error.message,
40
40
  }
41
41
  end
42
42
  end
@@ -13,7 +13,7 @@ module SolidusGraphqlApi
13
13
  field :order, Types::Order, null: true
14
14
  field :errors, [Types::UserError], null: false
15
15
 
16
- def resolve(payment_method:, amount: nil, source:)
16
+ def resolve(payment_method:, source:, amount: nil)
17
17
  current_order.update(state: :payment)
18
18
 
19
19
  update_params = {
@@ -3,7 +3,7 @@
3
3
  module SolidusGraphqlApi
4
4
  module Mutations
5
5
  module User
6
- class MarkDefaultAddress < BaseMutation
6
+ class MarkDefaultShipAddress < BaseMutation
7
7
  null true
8
8
 
9
9
  argument :address_id, ID, required: true, loads: Types::Address
@@ -11,7 +11,7 @@ module SolidusGraphqlApi
11
11
  field :user, Types::User, null: true
12
12
 
13
13
  def resolve(address:)
14
- current_user.mark_default_address(address)
14
+ current_user.mark_default_ship_address(address)
15
15
 
16
16
  { user: current_user.reload }
17
17
  end
@@ -4,16 +4,22 @@ module SolidusGraphqlApi
4
4
  module Mutations
5
5
  module User
6
6
  class SaveInAddressBook < BaseMutation
7
+ class AddressTypeInput < Types::Base::Enum
8
+ value "shipping"
9
+ value "billing"
10
+ end
11
+
7
12
  null true
8
13
 
9
14
  argument :address, Types::InputObjects::AddressInput, required: true
10
15
  argument :default, Boolean, required: false
16
+ argument :address_type, AddressTypeInput, required: false, default_value: "shipping"
11
17
 
12
18
  field :user, Types::User, null: true
13
19
  field :errors, [Types::UserError], null: false
14
20
 
15
- def resolve(address:, default: false)
16
- address = current_user.save_in_address_book(address, default)
21
+ def resolve(address:, address_type:, default: false)
22
+ address = current_user.save_in_address_book(address, default, address_type.to_sym)
17
23
 
18
24
  {
19
25
  user: current_user,
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusGraphqlApi
4
+ module Queries
5
+ module OptionValue
6
+ class OptionTypeQuery
7
+ attr_reader :option_value
8
+
9
+ def initialize(option_value:)
10
+ @option_value = option_value
11
+ end
12
+
13
+ def call
14
+ SolidusGraphqlApi::BatchLoader.for(option_value, :option_type)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusGraphqlApi
4
+ module Queries
5
+ module ShippingRate
6
+ class ShippingMethodQuery
7
+ attr_reader :shipping_rate
8
+
9
+ def initialize(shipping_rate:)
10
+ @shipping_rate = shipping_rate
11
+ end
12
+
13
+ def call
14
+ SolidusGraphqlApi::BatchLoader.for(shipping_rate, :shipping_method)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,7 +11,7 @@ module SolidusGraphqlApi
11
11
  end
12
12
 
13
13
  def call
14
- SolidusGraphqlApi::BatchLoader.for(variant, :default_price)
14
+ variant.default_price
15
15
  end
16
16
  end
17
17
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  FactoryBot.modify do
4
4
  factory :address do
5
- firstname { 'John' }
6
- lastname { nil }
5
+ name { 'John Von Doe' }
7
6
  end
8
7
  end
@@ -22,5 +22,15 @@ FactoryBot.modify do
22
22
  )
23
23
  end
24
24
  end
25
+
26
+ trait :with_root_icon do
27
+ after :create do |taxonomy|
28
+ taxonomy.root.update(icon: Spree::Core::Engine.root.join('lib',
29
+ 'spree',
30
+ 'testing_support',
31
+ 'fixtures',
32
+ 'blank.jpg').open)
33
+ end
34
+ end
25
35
  end
26
36
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_graphql_api/testing_support/factories/address_factory'
4
+ require 'solidus_graphql_api/testing_support/factories/country_factory'
5
+ require 'solidus_graphql_api/testing_support/factories/store_factory'
6
+ require 'solidus_graphql_api/testing_support/factories/taxonomy_factory'
7
+
8
+ FactoryBot.define do
9
+ end
@@ -12,8 +12,7 @@ module SolidusGraphqlApi
12
12
  field :company, String, null: true
13
13
  field :country, Country, null: false
14
14
  field :created_at, GraphQL::Types::ISO8601DateTime, null: true
15
- field :firstname, String, null: false
16
- field :lastname, String, null: true
15
+ field :name, String, null: false
17
16
  field :phone, String, null: false
18
17
  field :state_name, String, null: true
19
18
  field :state, State, null: true
@@ -4,7 +4,7 @@ module SolidusGraphqlApi
4
4
  module Types
5
5
  module Base
6
6
  class RelayNode < Base::Object
7
- implements GraphQL::Relay::Node.interface
7
+ implements GraphQL::Types::Relay::Node
8
8
 
9
9
  global_id_field :id
10
10
  end
@@ -12,8 +12,7 @@ module SolidusGraphqlApi
12
12
  argument :city, String, required: true
13
13
  argument :company, String, required: false
14
14
  argument :country_id, ID, required: true, loads: Types::Country
15
- argument :firstname, String, required: true
16
- argument :lastname, String, required: false
15
+ argument :name, String, required: true
17
16
  argument :phone, String, required: true
18
17
  argument :state_name, String, required: false
19
18
  argument :state_id, ID, required: false, loads: Types::State
@@ -4,6 +4,7 @@ module SolidusGraphqlApi
4
4
  module Types
5
5
  class Json < GraphQL::Types::JSON
6
6
  def self.coerce_input(value, ctx)
7
+ value = value.is_a?(ActionController::Parameters) ? value.permit!.to_h : value.to_h
7
8
  value.each do |key, field|
8
9
  case field
9
10
  when String
@@ -27,9 +28,10 @@ module SolidusGraphqlApi
27
28
 
28
29
  def self.decode_array(array, ctx)
29
30
  array.map do |value|
30
- if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
31
+ case value
32
+ when Hash, ActionController::Parameters
31
33
  coerce_input(value, ctx)
32
- elsif value.is_a?(String)
34
+ when String
33
35
  decode(value)
34
36
  else
35
37
  value
@@ -39,7 +41,8 @@ module SolidusGraphqlApi
39
41
 
40
42
  def self.decode_if_relay_id(value)
41
43
  GraphQL::Schema::UniqueWithinType.decode(value)
42
- rescue ArgumentError
44
+ # As of graphql v1.10.8 a GraphQL::ExecutionError is raised instead of an ArgumentError
45
+ rescue ArgumentError, GraphQL::ExecutionError
43
46
  [nil, nil]
44
47
  end
45
48
 
@@ -5,7 +5,7 @@ module SolidusGraphqlApi
5
5
  class Mutation < Base::Object
6
6
  field :save_in_address_book, mutation: Mutations::User::SaveInAddressBook
7
7
  field :remove_from_address_book, mutation: Mutations::User::RemoveFromAddressBook
8
- field :mark_default_address, mutation: Mutations::User::MarkDefaultAddress
8
+ field :mark_default_ship_address, mutation: Mutations::User::MarkDefaultShipAddress
9
9
  field :add_addresses_to_checkout, mutation: Mutations::Checkout::AddAddressesToCheckout
10
10
  field :select_shipping_rate, mutation: Mutations::Checkout::SelectShippingRate
11
11
  field :add_payment_to_checkout, mutation: Mutations::Checkout::AddPaymentToCheckout
@@ -10,6 +10,11 @@ module SolidusGraphqlApi
10
10
  field :position, String, null: false
11
11
  field :presentation, String, null: false
12
12
  field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
13
+ field :option_type, OptionType, null: false
14
+
15
+ def option_type
16
+ Queries::OptionValue::OptionTypeQuery.new(option_value: object).call
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -4,10 +4,10 @@ module SolidusGraphqlApi
4
4
  module Types
5
5
  class Query < Base::Object
6
6
  # Used by Relay to lookup objects by UUID:
7
- field :node, field: GraphQL::Relay::Node.field
7
+ add_field(GraphQL::Types::Relay::NodeField)
8
8
 
9
9
  # Fetches a list of objects given a list of UUIDs
10
- field :nodes, field: GraphQL::Relay::Node.plural_field
10
+ add_field(GraphQL::Types::Relay::NodesField)
11
11
 
12
12
  field :countries, Country.connection_type,
13
13
  null: false,
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusGraphqlApi
4
+ module Types
5
+ class ShippingMethod < Base::RelayNode
6
+ description 'Shipping Method.'
7
+
8
+ field :name, String, null: false
9
+ field :tracking_url, String, null: true
10
+ field :admin_name, String, null: true
11
+ field :code, String, null: true
12
+ field :carrier, String, null: true
13
+ field :service_level, String, null: true
14
+ field :available_to_users, Boolean, null: false
15
+ field :available_to_all, Boolean, null: false
16
+ field :created_at, GraphQL::Types::ISO8601DateTime, null: true
17
+ field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
18
+ end
19
+ end
20
+ end
@@ -10,6 +10,11 @@ module SolidusGraphqlApi
10
10
  field :currency, String, null: false
11
11
  field :selected, Boolean, null: false
12
12
  field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
13
+ field :shipping_method, ShippingMethod, null: false
14
+
15
+ def shipping_method
16
+ Queries::ShippingRate::ShippingMethodQuery.new(shipping_rate: object).call
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -9,7 +9,7 @@ module SolidusGraphqlApi
9
9
  field :bill_address, Types::Address, null: true
10
10
  field :created_at, GraphQL::Types::ISO8601DateTime, null: true
11
11
  field :current_sign_in_at, GraphQL::Types::ISO8601DateTime, null: true
12
- field :default_address, Types::Address, null: true
12
+ field :ship_address, Types::Address, null: true
13
13
  field :email, String, null: false
14
14
  field :last_sign_in_at, GraphQL::Types::ISO8601DateTime, null: true
15
15
  field :login, String, null: true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusGraphqlApi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -3,9 +3,6 @@
3
3
  require 'graphql'
4
4
  require 'batch-loader'
5
5
 
6
- require 'solidus_core'
7
- require 'solidus_support'
8
-
9
6
  require 'solidus_graphql_api/version'
10
7
  require 'solidus_graphql_api/engine'
11
8
  require 'solidus_graphql_api/configuration'