solidus_graphql_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +93 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +0 -0
- data/CONTRIBUTING.md +57 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/LICENSE.md +26 -0
- data/README.md +245 -0
- data/Rakefile +43 -0
- data/app/controllers/spree/graphql_controller.rb +49 -0
- data/bin/console +17 -0
- data/bin/rails +9 -0
- data/bin/rails-engine +16 -0
- data/bin/rails-sandbox +18 -0
- data/bin/rake +8 -0
- data/bin/sandbox +84 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +5 -0
- data/lib/generators/solidus_graphql_api/install/install_generator.rb +8 -0
- data/lib/solidus_graphql_api.rb +11 -0
- data/lib/solidus_graphql_api/batch_loader.rb +114 -0
- data/lib/solidus_graphql_api/batch_loader/belongs_to.rb +30 -0
- data/lib/solidus_graphql_api/batch_loader/has_many.rb +24 -0
- data/lib/solidus_graphql_api/batch_loader/has_many_through.rb +42 -0
- data/lib/solidus_graphql_api/batch_loader/has_one.rb +22 -0
- data/lib/solidus_graphql_api/configuration.rb +19 -0
- data/lib/solidus_graphql_api/context.rb +76 -0
- data/lib/solidus_graphql_api/engine.rb +25 -0
- data/lib/solidus_graphql_api/factories.rb +11 -0
- data/lib/solidus_graphql_api/factories/address_factory.rb +8 -0
- data/lib/solidus_graphql_api/factories/country_factory.rb +12 -0
- data/lib/solidus_graphql_api/factories/store_factory.rb +16 -0
- data/lib/solidus_graphql_api/factories/taxonomy_factory.rb +26 -0
- data/lib/solidus_graphql_api/mutations/.keep +0 -0
- data/lib/solidus_graphql_api/mutations/base_mutation.rb +45 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_addresses_to_checkout.rb +41 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_payment_to_checkout.rb +45 -0
- data/lib/solidus_graphql_api/mutations/checkout/add_to_cart.rb +30 -0
- data/lib/solidus_graphql_api/mutations/checkout/advance_checkout.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb +32 -0
- data/lib/solidus_graphql_api/mutations/checkout/complete_checkout.rb +31 -0
- data/lib/solidus_graphql_api/mutations/checkout/create_order.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/empty_cart.rb +29 -0
- data/lib/solidus_graphql_api/mutations/checkout/next_checkout_state.rb +27 -0
- data/lib/solidus_graphql_api/mutations/checkout/remove_from_cart.rb +33 -0
- data/lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb +40 -0
- data/lib/solidus_graphql_api/mutations/checkout/set_order_email.rb +29 -0
- data/lib/solidus_graphql_api/mutations/checkout/update_cart_quantity.rb +41 -0
- data/lib/solidus_graphql_api/mutations/user/mark_default_address.rb +31 -0
- data/lib/solidus_graphql_api/mutations/user/remove_from_address_book.rb +25 -0
- data/lib/solidus_graphql_api/mutations/user/save_in_address_book.rb +30 -0
- data/lib/solidus_graphql_api/queries/address/country_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/address/state_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/completed_orders_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/countries_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/country/states_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/line_item/variant_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/option_type/option_values_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/adjustments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/billing_address_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/line_items_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/payments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/shipments_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/order/shipping_address_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/master_variant_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/option_types_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/product_properties_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product/variants_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/product_by_slug_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/product_property/property_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/products_query.rb +29 -0
- data/lib/solidus_graphql_api/queries/shipment/shipping_rates_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxon/children_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxon/parent_taxon_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxonomies_query.rb +11 -0
- data/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/taxonomy/taxons_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/default_price_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/images_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/option_values_query.rb +19 -0
- data/lib/solidus_graphql_api/queries/variant/prices_query.rb +19 -0
- data/lib/solidus_graphql_api/schema.rb +40 -0
- data/lib/solidus_graphql_api/types/.keep +0 -0
- data/lib/solidus_graphql_api/types/address.rb +32 -0
- data/lib/solidus_graphql_api/types/base/argument.rb +10 -0
- data/lib/solidus_graphql_api/types/base/enum.rb +10 -0
- data/lib/solidus_graphql_api/types/base/field.rb +13 -0
- data/lib/solidus_graphql_api/types/base/input_object.rb +10 -0
- data/lib/solidus_graphql_api/types/base/interface.rb +11 -0
- data/lib/solidus_graphql_api/types/base/object.rb +25 -0
- data/lib/solidus_graphql_api/types/base/relay_node.rb +13 -0
- data/lib/solidus_graphql_api/types/base/scalar.rb +10 -0
- data/lib/solidus_graphql_api/types/base/union.rb +10 -0
- data/lib/solidus_graphql_api/types/country.rb +23 -0
- data/lib/solidus_graphql_api/types/credit_card.rb +18 -0
- data/lib/solidus_graphql_api/types/currency.rb +14 -0
- data/lib/solidus_graphql_api/types/image.rb +27 -0
- data/lib/solidus_graphql_api/types/input_objects/address_input.rb +24 -0
- data/lib/solidus_graphql_api/types/input_objects/products_query_input.rb +15 -0
- data/lib/solidus_graphql_api/types/interfaces/adjustment.rb +32 -0
- data/lib/solidus_graphql_api/types/interfaces/payment_source.rb +19 -0
- data/lib/solidus_graphql_api/types/json.rb +63 -0
- data/lib/solidus_graphql_api/types/line_item.rb +26 -0
- data/lib/solidus_graphql_api/types/manifest_item.rb +12 -0
- data/lib/solidus_graphql_api/types/mutation.rb +24 -0
- data/lib/solidus_graphql_api/types/option_type.rb +22 -0
- data/lib/solidus_graphql_api/types/option_value.rb +15 -0
- data/lib/solidus_graphql_api/types/order.rb +63 -0
- data/lib/solidus_graphql_api/types/payment.rb +15 -0
- data/lib/solidus_graphql_api/types/payment_method.rb +15 -0
- data/lib/solidus_graphql_api/types/price.rb +21 -0
- data/lib/solidus_graphql_api/types/product.rb +38 -0
- data/lib/solidus_graphql_api/types/product_property.rb +19 -0
- data/lib/solidus_graphql_api/types/promotion_adjustment.rb +17 -0
- data/lib/solidus_graphql_api/types/property.rb +14 -0
- data/lib/solidus_graphql_api/types/query.rb +84 -0
- data/lib/solidus_graphql_api/types/shipment.rb +23 -0
- data/lib/solidus_graphql_api/types/shipping_rate.rb +15 -0
- data/lib/solidus_graphql_api/types/state.rb +14 -0
- data/lib/solidus_graphql_api/types/store.rb +27 -0
- data/lib/solidus_graphql_api/types/tax_adjustment.rb +11 -0
- data/lib/solidus_graphql_api/types/taxon.rb +33 -0
- data/lib/solidus_graphql_api/types/taxonomy.rb +23 -0
- data/lib/solidus_graphql_api/types/user.rb +23 -0
- data/lib/solidus_graphql_api/types/user_error.rb +12 -0
- data/lib/solidus_graphql_api/types/variant.rb +39 -0
- data/lib/solidus_graphql_api/types/wallet_payment_source.rb +14 -0
- data/lib/solidus_graphql_api/version.rb +5 -0
- data/schema.graphql +2070 -0
- data/solidus_graphql_api.gemspec +43 -0
- data/spec/integration/mutations/add_to_cart_spec.rb +67 -0
- data/spec/integration/mutations/checkout/add_addresses_to_checkout_spec.rb +115 -0
- data/spec/integration/mutations/checkout/add_payment_to_checkout_spec.rb +87 -0
- data/spec/integration/mutations/checkout/advance_checkout_spec.rb +71 -0
- data/spec/integration/mutations/checkout/apply_coupon_code_spec.rb +76 -0
- data/spec/integration/mutations/checkout/complete_checkout_spec.rb +56 -0
- data/spec/integration/mutations/checkout/next_checkout_state_spec.rb +69 -0
- data/spec/integration/mutations/checkout/select_shipping_rate_spec.rb +89 -0
- data/spec/integration/mutations/create_order_spec.rb +55 -0
- data/spec/integration/mutations/empty_cart_spec.rb +58 -0
- data/spec/integration/mutations/mark_default_address_spec.rb +33 -0
- data/spec/integration/mutations/remove_from_address_book_spec.rb +48 -0
- data/spec/integration/mutations/remove_from_cart_spec.rb +65 -0
- data/spec/integration/mutations/save_in_address_book_spec.rb +90 -0
- data/spec/integration/mutations/set_order_email_spec.rb +61 -0
- data/spec/integration/mutations/update_cart_quantity_spec.rb +68 -0
- data/spec/integration/queries/completed_orders_spec.rb +158 -0
- data/spec/integration/queries/countries_spec.rb +18 -0
- data/spec/integration/queries/current_order_spec.rb +15 -0
- data/spec/integration/queries/current_store_spec.rb +15 -0
- data/spec/integration/queries/current_user_spec.rb +43 -0
- data/spec/integration/queries/product_by_slug_spec.rb +42 -0
- data/spec/integration/queries/products_spec.rb +40 -0
- data/spec/integration/queries/taxonomies_spec.rb +22 -0
- data/spec/lib/solidus_graphql_api/batch_loader/belongs_to_spec.rb +67 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_many_spec.rb +38 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_many_through_spec.rb +47 -0
- data/spec/lib/solidus_graphql_api/batch_loader/has_one_spec.rb +38 -0
- data/spec/lib/solidus_graphql_api/context_spec.rb +236 -0
- data/spec/lib/solidus_graphql_api/queries/address/country_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/address/state_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/completed_orders_query_spec.rb +12 -0
- data/spec/lib/solidus_graphql_api/queries/countries_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/country/states_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/line_item/variant_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/option_type/option_values_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/order/adjustments_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/order/billing_address_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/order/line_items_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/order/payments_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/order/shipments_query_spec.rb +18 -0
- data/spec/lib/solidus_graphql_api/queries/order/shipping_address_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/master_variant_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/option_types_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/product_properties_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product/variants_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/product_by_slug_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/queries/product_property/property_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/products_query_spec.rb +49 -0
- data/spec/lib/solidus_graphql_api/queries/shipment/shipping_rates_query_spec.rb +18 -0
- data/spec/lib/solidus_graphql_api/queries/taxon/children_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/taxon/parent_taxon_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomies_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomy/root_taxon_query_spec.rb +10 -0
- data/spec/lib/solidus_graphql_api/queries/taxonomy/taxons_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/default_price_query_spec.rb +9 -0
- data/spec/lib/solidus_graphql_api/queries/variant/images_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/option_values_query_spec.rb +11 -0
- data/spec/lib/solidus_graphql_api/queries/variant/prices_query_spec.rb +13 -0
- data/spec/lib/solidus_graphql_api/schema_spec.rb +80 -0
- data/spec/lib/solidus_graphql_api/types/base/object_spec.rb +29 -0
- data/spec/lib/solidus_graphql_api/types/json_spec.rb +115 -0
- data/spec/lib/solidus_graphql_api/types/option_type_spec.rb +7 -0
- data/spec/lib/solidus_graphql_api/types/product_property_spec.rb +22 -0
- data/spec/lib/solidus_graphql_api/types/product_spec.rb +56 -0
- data/spec/lib/solidus_graphql_api/types/query_spec.rb +33 -0
- data/spec/lib/solidus_graphql_api/types/variant_spec.rb +58 -0
- data/spec/requests/spree/graphql_controller_spec.rb +17 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/expected_schema.graphql +2070 -0
- data/spec/support/graphql/mutations/add_addresses_to_checkout.gql +19 -0
- data/spec/support/graphql/mutations/add_payment_to_checkout.gql +13 -0
- data/spec/support/graphql/mutations/add_to_cart.gql +21 -0
- data/spec/support/graphql/mutations/advance_checkout.gql +13 -0
- data/spec/support/graphql/mutations/apply_coupon_code.gql +13 -0
- data/spec/support/graphql/mutations/complete_checkout.gql +13 -0
- data/spec/support/graphql/mutations/create_order.gql +11 -0
- data/spec/support/graphql/mutations/empty_cart.gql +17 -0
- data/spec/support/graphql/mutations/mark_default_address.gql +9 -0
- data/spec/support/graphql/mutations/next_checkout_state.gql +13 -0
- data/spec/support/graphql/mutations/remove_from_address_book.gql +14 -0
- data/spec/support/graphql/mutations/remove_from_cart.gql +17 -0
- data/spec/support/graphql/mutations/save_in_address_book.gql +57 -0
- data/spec/support/graphql/mutations/select_shipping_rate.gql +23 -0
- data/spec/support/graphql/mutations/set_order_email.gql +13 -0
- data/spec/support/graphql/mutations/update_cart_quantity.gql +18 -0
- data/spec/support/graphql/queries/completed_orders.gql +29 -0
- data/spec/support/graphql/queries/completed_orders/adjustments.gql +24 -0
- data/spec/support/graphql/queries/completed_orders/available_payment_methods.gql +15 -0
- data/spec/support/graphql/queries/completed_orders/billing_address.gql +40 -0
- data/spec/support/graphql/queries/completed_orders/line_items.gql +23 -0
- data/spec/support/graphql/queries/completed_orders/payments.gql +23 -0
- data/spec/support/graphql/queries/completed_orders/shipping_address.gql +40 -0
- data/spec/support/graphql/queries/countries.gql +24 -0
- data/spec/support/graphql/queries/current_order.gql +32 -0
- data/spec/support/graphql/queries/current_store.gql +24 -0
- data/spec/support/graphql/queries/current_user.gql +197 -0
- data/spec/support/graphql/queries/product_by_slug.gql +106 -0
- data/spec/support/graphql/queries/products.gql +7 -0
- data/spec/support/graphql/queries/taxonomies.gql +81 -0
- data/spec/support/graphql/responses/completed_orders.json.erb +58 -0
- data/spec/support/graphql/responses/completed_orders/adjustments.json.erb +34 -0
- data/spec/support/graphql/responses/completed_orders/available_payment_methods.json.erb +29 -0
- data/spec/support/graphql/responses/completed_orders/billing_address.json.erb +78 -0
- data/spec/support/graphql/responses/completed_orders/line_items.json.erb +43 -0
- data/spec/support/graphql/responses/completed_orders/payments.json.erb +27 -0
- data/spec/support/graphql/responses/completed_orders/shipping_address.json.erb +78 -0
- data/spec/support/graphql/responses/countries.json.erb +51 -0
- data/spec/support/graphql/responses/current_order.json.erb +36 -0
- data/spec/support/graphql/responses/current_store.json.erb +34 -0
- data/spec/support/graphql/responses/current_user.json.erb +232 -0
- data/spec/support/graphql/responses/product_by_slug.json.erb +123 -0
- data/spec/support/graphql/responses/taxonomies.json.erb +145 -0
- data/spec/support/helpers/graphql.rb +43 -0
- data/spec/support/matchers/graphql.rb +35 -0
- data/spec/support/shared_contexts/graphql_query_subject.rb +21 -0
- metadata +572 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
module Interfaces
|
6
|
+
module PaymentSource
|
7
|
+
include Types::Base::Interface
|
8
|
+
|
9
|
+
orphan_types(*SolidusGraphqlApi.configuration.payment_sources.map(&:constantize))
|
10
|
+
|
11
|
+
description "Payment Source."
|
12
|
+
|
13
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
14
|
+
field :payment_method, Types::PaymentMethod, null: false
|
15
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Json < GraphQL::Types::JSON
|
6
|
+
def self.coerce_input(value, ctx)
|
7
|
+
value.each do |key, field|
|
8
|
+
case field
|
9
|
+
when String
|
10
|
+
value[key] = decode(field)
|
11
|
+
when Array
|
12
|
+
value[key] = decode_array(field, ctx)
|
13
|
+
when Hash, ActionController::Parameters
|
14
|
+
value[key] = coerce_input(field, ctx)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
value
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.decode(value)
|
21
|
+
class_name, item_id = decode_if_relay_id(value)
|
22
|
+
|
23
|
+
return value unless class_exists?(class_name)
|
24
|
+
|
25
|
+
to_i_or_nil(item_id) || value
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.decode_array(array, ctx)
|
29
|
+
array.map do |value|
|
30
|
+
if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
|
31
|
+
coerce_input(value, ctx)
|
32
|
+
elsif value.is_a?(String)
|
33
|
+
decode(value)
|
34
|
+
else
|
35
|
+
value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.decode_if_relay_id(value)
|
41
|
+
GraphQL::Schema::UniqueWithinType.decode(value)
|
42
|
+
rescue ArgumentError
|
43
|
+
[nil, nil]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.class_exists?(value)
|
47
|
+
return false if value.nil?
|
48
|
+
|
49
|
+
Object.const_defined?(value)
|
50
|
+
rescue NameError
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.to_i_or_nil(value)
|
55
|
+
return value if value.nil?
|
56
|
+
|
57
|
+
Integer(value)
|
58
|
+
rescue ArgumentError
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class LineItem < Base::RelayNode
|
6
|
+
description 'Line item.'
|
7
|
+
|
8
|
+
field :additional_tax_total, Float, null: false
|
9
|
+
field :adjustment_total, Float, null: false
|
10
|
+
field :amount, Float, null: false
|
11
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
12
|
+
field :currency, String, null: false
|
13
|
+
field :has_sufficient_stock, Boolean, null: false, method: :sufficient_stock?
|
14
|
+
field :included_tax_total, Float, null: false
|
15
|
+
field :price, Float, null: false
|
16
|
+
field :promo_total, Float, null: false
|
17
|
+
field :quantity, Integer, null: false
|
18
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
19
|
+
field :variant, Variant, null: false
|
20
|
+
|
21
|
+
def variant
|
22
|
+
Queries::LineItem::VariantQuery.new(line_item: object).call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class ManifestItem < Base::Object
|
6
|
+
description 'Shipping Manifest Item.'
|
7
|
+
|
8
|
+
field :variant, Types::Variant, null: false
|
9
|
+
field :quantity, Integer, null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Mutation < Base::Object
|
6
|
+
field :save_in_address_book, mutation: Mutations::User::SaveInAddressBook
|
7
|
+
field :remove_from_address_book, mutation: Mutations::User::RemoveFromAddressBook
|
8
|
+
field :mark_default_address, mutation: Mutations::User::MarkDefaultAddress
|
9
|
+
field :add_addresses_to_checkout, mutation: Mutations::Checkout::AddAddressesToCheckout
|
10
|
+
field :select_shipping_rate, mutation: Mutations::Checkout::SelectShippingRate
|
11
|
+
field :add_payment_to_checkout, mutation: Mutations::Checkout::AddPaymentToCheckout
|
12
|
+
field :next_checkout_state, mutation: Mutations::Checkout::NextCheckoutState
|
13
|
+
field :advance_checkout, mutation: Mutations::Checkout::AdvanceCheckout
|
14
|
+
field :complete_checkout, mutation: Mutations::Checkout::CompleteCheckout
|
15
|
+
field :create_order, mutation: Mutations::Checkout::CreateOrder
|
16
|
+
field :add_to_cart, mutation: Mutations::Checkout::AddToCart
|
17
|
+
field :remove_from_cart, mutation: Mutations::Checkout::RemoveFromCart
|
18
|
+
field :empty_cart, mutation: Mutations::Checkout::EmptyCart
|
19
|
+
field :update_cart_quantity, mutation: Mutations::Checkout::UpdateCartQuantity
|
20
|
+
field :apply_coupon_code, mutation: Mutations::Checkout::ApplyCouponCode
|
21
|
+
field :set_order_email, mutation: Mutations::Checkout::SetOrderEmail
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class OptionType < Base::RelayNode
|
6
|
+
graphql_name 'OptionType'
|
7
|
+
|
8
|
+
description 'OptionType Type.'
|
9
|
+
|
10
|
+
field :name, String, null: false
|
11
|
+
field :presentation, String, null: false
|
12
|
+
field :position, Int, null: false
|
13
|
+
field :option_values, OptionValue.connection_type, null: false
|
14
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
15
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
16
|
+
|
17
|
+
def option_values
|
18
|
+
Queries::OptionType::OptionValuesQuery.new(option_type: object).call
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class OptionValue < Base::RelayNode
|
6
|
+
description 'OptionValue.'
|
7
|
+
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :name, String, null: false
|
10
|
+
field :position, String, null: false
|
11
|
+
field :presentation, String, null: false
|
12
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Order < Base::RelayNode
|
6
|
+
description 'Order.'
|
7
|
+
|
8
|
+
field :additional_tax_total, String, null: false
|
9
|
+
field :adjustment_total, String, null: false
|
10
|
+
field :adjustments, Types::Interfaces::Adjustment.connection_type, null: false
|
11
|
+
field :approved_at, GraphQL::Types::ISO8601DateTime, null: true
|
12
|
+
field :billing_address, Address, null: true
|
13
|
+
field :canceled_at, GraphQL::Types::ISO8601DateTime, null: true
|
14
|
+
field :completed_at, GraphQL::Types::ISO8601DateTime, null: true
|
15
|
+
field :confirmation_delivered, Boolean, null: false
|
16
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
17
|
+
field :currency, String, null: false
|
18
|
+
field :email, String, null: true
|
19
|
+
field :guest_token, String, null: true
|
20
|
+
field :included_tax_total, String, null: false
|
21
|
+
field :item_total, String, null: false
|
22
|
+
field :line_items, LineItem.connection_type, null: false
|
23
|
+
field :number, String, null: false
|
24
|
+
field :available_payment_methods, [PaymentMethod], null: false
|
25
|
+
field :payment_state, String, null: false
|
26
|
+
field :payment_total, String, null: false
|
27
|
+
field :payments, [Payment], null: false
|
28
|
+
field :promo_total, String, null: false
|
29
|
+
field :shipment_state, String, null: false
|
30
|
+
field :shipment_total, String, null: false
|
31
|
+
field :shipments, Shipment.connection_type, null: false
|
32
|
+
field :shipping_address, Address, null: true
|
33
|
+
field :special_instructions, String, null: true
|
34
|
+
field :state, String, null: false
|
35
|
+
field :total, String, null: false
|
36
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
37
|
+
|
38
|
+
def adjustments
|
39
|
+
Queries::Order::AdjustmentsQuery.new(order: object).call
|
40
|
+
end
|
41
|
+
|
42
|
+
def billing_address
|
43
|
+
Queries::Order::BillingAddressQuery.new(order: object).call
|
44
|
+
end
|
45
|
+
|
46
|
+
def line_items
|
47
|
+
Queries::Order::LineItemsQuery.new(order: object).call
|
48
|
+
end
|
49
|
+
|
50
|
+
def payments
|
51
|
+
Queries::Order::PaymentsQuery.new(order: object).call
|
52
|
+
end
|
53
|
+
|
54
|
+
def shipments
|
55
|
+
Queries::Order::ShipmentsQuery.new(order: object).call
|
56
|
+
end
|
57
|
+
|
58
|
+
def shipping_address
|
59
|
+
Queries::Order::ShippingAddressQuery.new(order: object).call
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Payment < Base::RelayNode
|
6
|
+
description 'Payment.'
|
7
|
+
|
8
|
+
field :amount, String, null: true
|
9
|
+
field :state, String, null: false
|
10
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
11
|
+
field :payment_source, Types::Interfaces::PaymentSource, null: true
|
12
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class PaymentMethod < Base::RelayNode
|
6
|
+
description 'Payment Method.'
|
7
|
+
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :description, String, null: true
|
10
|
+
field :name, String, null: false
|
11
|
+
field :position, String, null: false
|
12
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Price < Base::RelayNode
|
6
|
+
description 'Price.'
|
7
|
+
|
8
|
+
field :amount, String, null: false
|
9
|
+
field :country_iso, String, null: true
|
10
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
11
|
+
field :currency, Currency, null: false
|
12
|
+
field :display_amount, String, null: false
|
13
|
+
field :display_country, String, null: false
|
14
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
15
|
+
|
16
|
+
def currency
|
17
|
+
object.display_amount.currency
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Product < Base::RelayNode
|
6
|
+
description 'Product.'
|
7
|
+
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :description, String, null: true
|
10
|
+
field :master_variant, Variant, null: false
|
11
|
+
field :meta_description, String, null: true
|
12
|
+
field :meta_keywords, String, null: true
|
13
|
+
field :meta_title, String, null: true
|
14
|
+
field :name, String, null: false
|
15
|
+
field :option_types, OptionType.connection_type, null: false
|
16
|
+
field :product_properties, ProductProperty.connection_type, null: false
|
17
|
+
field :slug, String, null: false
|
18
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
19
|
+
field :variants, Variant.connection_type, null: false
|
20
|
+
|
21
|
+
def master_variant
|
22
|
+
Queries::Product::MasterVariantQuery.new(product: object).call
|
23
|
+
end
|
24
|
+
|
25
|
+
def option_types
|
26
|
+
Queries::Product::OptionTypesQuery.new(product: object).call
|
27
|
+
end
|
28
|
+
|
29
|
+
def product_properties
|
30
|
+
Queries::Product::ProductPropertiesQuery.new(product: object).call
|
31
|
+
end
|
32
|
+
|
33
|
+
def variants
|
34
|
+
Queries::Product::VariantsQuery.new(product: object).call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class ProductProperty < Base::RelayNode
|
6
|
+
description 'Product Property.'
|
7
|
+
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :position, Int, null: false
|
10
|
+
field :property, Property, null: true
|
11
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
12
|
+
field :value, String, null: true
|
13
|
+
|
14
|
+
def property
|
15
|
+
Queries::ProductProperty::PropertyQuery.new(product_property: object).call
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class PromotionAdjustment < Base::RelayNode
|
6
|
+
implements Types::Interfaces::Adjustment
|
7
|
+
|
8
|
+
description 'PromotionAdjustment.'
|
9
|
+
|
10
|
+
field :promotion_code, String, null: true
|
11
|
+
|
12
|
+
def promotion_code
|
13
|
+
object.promotion_code&.value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Property < Base::RelayNode
|
6
|
+
description 'Property.'
|
7
|
+
|
8
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
9
|
+
field :name, String, null: false
|
10
|
+
field :presentation, String, null: false
|
11
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Query < Base::Object
|
6
|
+
# Used by Relay to lookup objects by UUID:
|
7
|
+
field :node, field: GraphQL::Relay::Node.field
|
8
|
+
|
9
|
+
# Fetches a list of objects given a list of UUIDs
|
10
|
+
field :nodes, field: GraphQL::Relay::Node.plural_field
|
11
|
+
|
12
|
+
field :countries, Country.connection_type,
|
13
|
+
null: false,
|
14
|
+
description: 'Supported Countries.'
|
15
|
+
|
16
|
+
field :completed_orders, Order.connection_type,
|
17
|
+
null: false,
|
18
|
+
description: 'Customer Completed Orders.'
|
19
|
+
|
20
|
+
field :products, Product.connection_type,
|
21
|
+
null: false,
|
22
|
+
description: 'Supported Products.' do
|
23
|
+
argument :query, Types::InputObjects::ProductsQueryInput, required: false
|
24
|
+
end
|
25
|
+
|
26
|
+
field :product_by_slug, Product,
|
27
|
+
null: true,
|
28
|
+
description: 'Find a product by its slug.' do
|
29
|
+
argument :slug, String, required: true
|
30
|
+
end
|
31
|
+
|
32
|
+
field :taxonomies, Taxonomy.connection_type,
|
33
|
+
null: false,
|
34
|
+
description: 'Supported Taxonomies.'
|
35
|
+
|
36
|
+
field :current_user, Types::User,
|
37
|
+
null: true,
|
38
|
+
description: 'Current logged User.'
|
39
|
+
|
40
|
+
field :current_store, Types::Store,
|
41
|
+
null: true,
|
42
|
+
description: 'Current Store.'
|
43
|
+
|
44
|
+
field :current_order, Types::Order,
|
45
|
+
null: true,
|
46
|
+
description: 'Current Order.'
|
47
|
+
|
48
|
+
def countries
|
49
|
+
Queries::CountriesQuery.new.call
|
50
|
+
end
|
51
|
+
|
52
|
+
def completed_orders
|
53
|
+
Queries::CompletedOrdersQuery.new(user: context[:current_user]).call
|
54
|
+
end
|
55
|
+
|
56
|
+
def products(query: {})
|
57
|
+
Queries::ProductsQuery.new(
|
58
|
+
user: context[:current_user],
|
59
|
+
pricing_options: context[:current_pricing_options]
|
60
|
+
).call(query: query)
|
61
|
+
end
|
62
|
+
|
63
|
+
def product_by_slug(slug:)
|
64
|
+
Queries::ProductBySlugQuery.new.call(slug: slug)
|
65
|
+
end
|
66
|
+
|
67
|
+
def taxonomies
|
68
|
+
Queries::TaxonomiesQuery.new.call
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_user
|
72
|
+
context[:current_user]
|
73
|
+
end
|
74
|
+
|
75
|
+
def current_store
|
76
|
+
context[:current_store]
|
77
|
+
end
|
78
|
+
|
79
|
+
def current_order
|
80
|
+
context[:current_order]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|