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 Queries
|
5
|
+
module Taxonomy
|
6
|
+
class TaxonsQuery
|
7
|
+
attr_reader :taxonomy
|
8
|
+
|
9
|
+
def initialize(taxonomy:)
|
10
|
+
@taxonomy = taxonomy
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
SolidusGraphqlApi::BatchLoader.for(taxonomy, :taxons, scope: Spree::Taxon.order(:position, :id))
|
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 Variant
|
6
|
+
class DefaultPriceQuery
|
7
|
+
attr_reader :variant
|
8
|
+
|
9
|
+
def initialize(variant:)
|
10
|
+
@variant = variant
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
SolidusGraphqlApi::BatchLoader.for(variant, :default_price)
|
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 Variant
|
6
|
+
class ImagesQuery
|
7
|
+
attr_reader :variant
|
8
|
+
|
9
|
+
def initialize(variant:)
|
10
|
+
@variant = variant
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
SolidusGraphqlApi::BatchLoader.for(variant, :images)
|
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 Variant
|
6
|
+
class OptionValuesQuery
|
7
|
+
attr_reader :variant
|
8
|
+
|
9
|
+
def initialize(variant:)
|
10
|
+
@variant = variant
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
SolidusGraphqlApi::BatchLoader.for(variant, :option_values)
|
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 Variant
|
6
|
+
class PricesQuery
|
7
|
+
attr_reader :variant
|
8
|
+
|
9
|
+
def initialize(variant:)
|
10
|
+
@variant = variant
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
SolidusGraphqlApi::BatchLoader.for(variant, :prices)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
class Schema < GraphQL::Schema
|
5
|
+
query Types::Query
|
6
|
+
mutation Types::Mutation
|
7
|
+
|
8
|
+
use ::BatchLoader::GraphQL
|
9
|
+
|
10
|
+
rescue_from CanCan::AccessDenied do |exception|
|
11
|
+
raise GraphQL::ExecutionError, exception.message
|
12
|
+
end
|
13
|
+
|
14
|
+
rescue_from ActiveRecord::RecordNotFound do
|
15
|
+
raise GraphQL::ExecutionError, I18n.t(:'activerecord.exceptions.not_found')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Relay Object Identification:
|
19
|
+
class << self
|
20
|
+
# Return a string UUID for object
|
21
|
+
def id_from_object(object, _type_definition, _query_ctx)
|
22
|
+
GraphQL::Schema::UniqueWithinType.encode(object.class.name, object.id)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Given a string UUID, find the object
|
26
|
+
def object_from_id(id, _query_ctx)
|
27
|
+
class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
|
28
|
+
|
29
|
+
::Object.const_get(class_name).find(item_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Object Resolution
|
33
|
+
def resolve_type(_type_definition, object, _query_ctx)
|
34
|
+
class_name = object.is_a?(Spree::PaymentMethod) ? "PaymentMethod" : object.class.name.demodulize
|
35
|
+
|
36
|
+
Types.const_get(class_name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Address < Base::RelayNode
|
6
|
+
description 'Address.'
|
7
|
+
|
8
|
+
field :address1, String, null: false
|
9
|
+
field :address2, String, null: true
|
10
|
+
field :alternative_phone, String, null: true
|
11
|
+
field :city, String, null: false
|
12
|
+
field :company, String, null: true
|
13
|
+
field :country, Country, null: false
|
14
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
15
|
+
field :firstname, String, null: false
|
16
|
+
field :lastname, String, null: true
|
17
|
+
field :phone, String, null: false
|
18
|
+
field :state_name, String, null: true
|
19
|
+
field :state, State, null: true
|
20
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
21
|
+
field :zipcode, String, null: false
|
22
|
+
|
23
|
+
def state
|
24
|
+
Queries::Address::StateQuery.new(address: object).call
|
25
|
+
end
|
26
|
+
|
27
|
+
def country
|
28
|
+
Queries::Address::CountryQuery.new(address: object).call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
module Base
|
6
|
+
class Object < GraphQL::Schema::Object
|
7
|
+
class << self
|
8
|
+
# Removes a field from this schema.
|
9
|
+
#
|
10
|
+
# @param field [Symbol] the field to remove
|
11
|
+
#
|
12
|
+
# @example Removing a field in a decorator
|
13
|
+
# Spree::Graphql::Types::Variant.remove_field :prices
|
14
|
+
def remove_field(field)
|
15
|
+
unless own_fields.key?(field.to_s)
|
16
|
+
raise ArgumentError, "Field `#{field}` is not defined"
|
17
|
+
end
|
18
|
+
|
19
|
+
own_fields.delete(field.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Country < Base::RelayNode
|
6
|
+
description 'Country.'
|
7
|
+
|
8
|
+
field :iso_name, String, null: false
|
9
|
+
field :iso, String, null: false
|
10
|
+
field :iso3, String, null: false
|
11
|
+
field :name, String, null: false
|
12
|
+
field :numcode, Integer, null: false
|
13
|
+
field :states, State.connection_type, null: false
|
14
|
+
field :states_required, Boolean, null: false
|
15
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
16
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
17
|
+
|
18
|
+
def states
|
19
|
+
Queries::Country::StatesQuery.new(country: object).call
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class CreditCard < Base::RelayNode
|
6
|
+
implements Types::Interfaces::PaymentSource
|
7
|
+
|
8
|
+
description 'Credit Card.'
|
9
|
+
|
10
|
+
field :address, Address, null: false
|
11
|
+
field :cc_type, String, null: true
|
12
|
+
field :last_digits, String, null: false
|
13
|
+
field :month, String, null: false
|
14
|
+
field :name, String, null: false
|
15
|
+
field :year, String, null: false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Currency < Base::RelayNode
|
6
|
+
description 'Currency.'
|
7
|
+
|
8
|
+
field :html_entity, String, null: false
|
9
|
+
field :iso_code, String, null: false
|
10
|
+
field :name, String, null: false
|
11
|
+
field :symbol, String, null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
class Image < Base::RelayNode
|
6
|
+
description 'Image.'
|
7
|
+
|
8
|
+
field :alt, String, null: true
|
9
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
10
|
+
field :filename, String, null: false
|
11
|
+
field :large_url, String, null: false
|
12
|
+
field :mini_url, String, null: false
|
13
|
+
field :position, Integer, null: false
|
14
|
+
field :product_url, String, null: false
|
15
|
+
field :small_url, String, null: false
|
16
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
17
|
+
|
18
|
+
def large_url; object.url(:large) end
|
19
|
+
|
20
|
+
def mini_url; object.url(:mini) end
|
21
|
+
|
22
|
+
def product_url; object.url(:product) end
|
23
|
+
|
24
|
+
def small_url; object.url(:small) end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
module InputObjects
|
6
|
+
class AddressInput < Base::InputObject
|
7
|
+
description "Address."
|
8
|
+
|
9
|
+
argument :address1, String, required: true
|
10
|
+
argument :address2, String, required: false
|
11
|
+
argument :alternative_phone, String, required: false
|
12
|
+
argument :city, String, required: true
|
13
|
+
argument :company, String, required: false
|
14
|
+
argument :country_id, ID, required: true, loads: Types::Country
|
15
|
+
argument :firstname, String, required: true
|
16
|
+
argument :lastname, String, required: false
|
17
|
+
argument :phone, String, required: true
|
18
|
+
argument :state_name, String, required: false
|
19
|
+
argument :state_id, ID, required: false, loads: Types::State
|
20
|
+
argument :zipcode, String, required: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
module InputObjects
|
6
|
+
class ProductsQueryInput < Base::InputObject
|
7
|
+
description "Params for searching products."
|
8
|
+
|
9
|
+
argument :taxon, ID, "Taxon", required: false, loads: Types::Taxon
|
10
|
+
argument :keywords, String, "Keywords", required: false
|
11
|
+
argument :search, Types::Json, "Search", required: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusGraphqlApi
|
4
|
+
module Types
|
5
|
+
module Interfaces
|
6
|
+
module Adjustment
|
7
|
+
include Types::Base::Interface
|
8
|
+
|
9
|
+
description "Adjustment."
|
10
|
+
|
11
|
+
orphan_types Types::TaxAdjustment, Types::PromotionAdjustment
|
12
|
+
|
13
|
+
field :amount, String, null: false
|
14
|
+
field :created_at, GraphQL::Types::ISO8601DateTime, null: true
|
15
|
+
field :eligible, Boolean, null: false
|
16
|
+
field :label, String, null: false
|
17
|
+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
|
18
|
+
|
19
|
+
definition_methods do
|
20
|
+
def resolve_type(object, _context)
|
21
|
+
case object.source_type
|
22
|
+
when Spree::TaxRate.to_s
|
23
|
+
Types::TaxAdjustment
|
24
|
+
when Spree::PromotionAction.to_s
|
25
|
+
Types::PromotionAdjustment
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|