From 75f28bf1140cc8c20d72f15334b3a00127c925cc Mon Sep 17 00:00:00 2001 From: Christopher Pappas Date: Wed, 4 Mar 2020 21:29:47 -0800 Subject: [PATCH] [Stitching] Ensure schema matches existing MPv2 definitions --- .../add_asset_to_consignment_submission.rb | 14 +++++--- ...ssion.rb => create_submission_mutation.rb} | 32 +++++++++++-------- ...ssion.rb => update_submission_mutation.rb} | 31 ++++++++++-------- app/graph/types/asset_type.rb | 1 + app/graph/types/mutation_type.rb | 12 +++---- app/graph/types/submission_type.rb | 1 + 6 files changed, 52 insertions(+), 39 deletions(-) rename app/graph/mutations/{create_consignment_submission.rb => create_submission_mutation.rb} (55%) rename app/graph/mutations/{update_consignment_submission.rb => update_submission_mutation.rb} (64%) diff --git a/app/graph/mutations/add_asset_to_consignment_submission.rb b/app/graph/mutations/add_asset_to_consignment_submission.rb index e826bb565..e70826b2e 100644 --- a/app/graph/mutations/add_asset_to_consignment_submission.rb +++ b/app/graph/mutations/add_asset_to_consignment_submission.rb @@ -6,9 +6,9 @@ module AddAssetToConsignmentSubmission GraphQL::Relay::Mutation.define do name 'AddAssetToConsignmentSubmission' - input_field :submission_id, !types.ID - input_field :gemini_token, !types.String - input_field :asset_type, types.String + input_field :submissionID, !types.ID + input_field :geminiToken, !types.String + input_field :assetType, types.String return_field :asset, Types::AssetType end @@ -17,7 +17,7 @@ def self.resolve(_obj, args, context) params = args.to_h['input'].except('clientMutationId') client_mutation_id = args.to_h['input']['clientMutationId'] - submission = Submission.find_by(id: params['submission_id']) + submission = Submission.find_by(id: params['submissionID']) unless submission raise(GraphQL::ExecutionError, 'Submission from ID Not Found') end @@ -30,7 +30,11 @@ def self.resolve(_obj, args, context) raise(GraphQL::ExecutionError, 'Submission from ID Not Found') end - params['asset_type'] ||= 'image' + params['assetType'] ||= 'image' + + # Metaphysics uses camelCase properties and inputs + params = params.transform_keys(&:underscore) + asset = submission.assets.create!(params) SubmissionService.notify_user(submission.id) if submission.submitted? OpenStruct.new(asset: asset, client_mutation_id: client_mutation_id) diff --git a/app/graph/mutations/create_consignment_submission.rb b/app/graph/mutations/create_submission_mutation.rb similarity index 55% rename from app/graph/mutations/create_consignment_submission.rb rename to app/graph/mutations/create_submission_mutation.rb index acd11c7fe..8f2aabc5c 100644 --- a/app/graph/mutations/create_consignment_submission.rb +++ b/app/graph/mutations/create_submission_mutation.rb @@ -1,27 +1,27 @@ # frozen_string_literal: true module Mutations - module CreateConsignmentSubmission + module CreateSubmissionMutation Definition = GraphQL::Relay::Mutation.define do - name 'CreateConsignmentSubmission' + name 'CreateSubmissionMutation' - input_field :additional_info, types.String - input_field :artist_id, !types.String - input_field :authenticity_certificate, types.Boolean + input_field :additionalInfo, types.String + input_field :artistID, !types.String + input_field :authenticityCertificate, types.Boolean input_field :category, Types::CategoryType input_field :currency, types.String input_field :depth, types.String - input_field :dimensions_metric, types.String + input_field :dimensionsMetric, types.String input_field :edition, types.Boolean - input_field :edition_number, types.String - input_field :edition_size, types.Int + input_field :editionNumber, types.String + input_field :editionSize, types.Int input_field :height, types.String - input_field :location_city, types.String - input_field :location_country, types.String - input_field :location_state, types.String + input_field :locationCity, types.String + input_field :locationCountry, types.String + input_field :locationState, types.String input_field :medium, types.String - input_field :minimum_price_dollars, types.Int + input_field :minimumPriceDollars, types.Int input_field :provenance, types.String input_field :signature, types.Boolean input_field :state, Types::StateType @@ -29,16 +29,20 @@ module CreateConsignmentSubmission input_field :width, types.String input_field :year, types.String - return_field :consignment_submission, Types::SubmissionType + return_field :consignmentSubmission, Types::SubmissionType end def self.resolve(_obj, args, context) params = args.to_h['input'].except('clientMutationId') client_mutation_id = args.to_h['input']['clientMutationId'] + + # Metaphysics uses camelCase properties and inputs + params = params.transform_keys(&:underscore) + submission = SubmissionService.create_submission(params, context[:current_user]) OpenStruct.new( - consignment_submission: submission, + consignmentSubmission: submission, client_mutation_id: client_mutation_id ) end diff --git a/app/graph/mutations/update_consignment_submission.rb b/app/graph/mutations/update_submission_mutation.rb similarity index 64% rename from app/graph/mutations/update_consignment_submission.rb rename to app/graph/mutations/update_submission_mutation.rb index 888b35979..8ea1e684b 100644 --- a/app/graph/mutations/update_consignment_submission.rb +++ b/app/graph/mutations/update_submission_mutation.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true module Mutations - module UpdateConsignmentSubmission + module UpdateSubmissionMutation Definition = GraphQL::Relay::Mutation.define do - name 'UpdateConsignmentSubmission' + name 'UpdateSubmissionMutation' input_field :id, !types.ID - input_field :additional_info, types.String - input_field :artist_id, types.String - input_field :authenticity_certificate, types.Boolean + input_field :additionalInfo, types.String + input_field :artistID, types.String + input_field :authenticityCertificate, types.Boolean input_field :category, Types::CategoryType input_field :currency, types.String input_field :depth, types.String - input_field :dimensions_metric, types.String + input_field :dimensionsMetric, types.String input_field :edition, types.Boolean - input_field :edition_number, types.String - input_field :edition_size, types.Int + input_field :editionNumber, types.String + input_field :editionSize, types.Int input_field :height, types.String - input_field :location_city, types.String - input_field :location_country, types.String - input_field :location_state, types.String + input_field :locationCity, types.String + input_field :locationCountry, types.String + input_field :locationState, types.String input_field :medium, types.String - input_field :minimum_price_dollars, types.Int + input_field :minimumPriceDollars, types.Int input_field :provenance, types.String input_field :signature, types.Boolean input_field :state, Types::StateType @@ -30,13 +30,16 @@ module UpdateConsignmentSubmission input_field :width, types.String input_field :year, types.String - return_field :consignment_submission, Types::SubmissionType + return_field :consignmentSubmission, Types::SubmissionType end def self.resolve(_obj, args, context) params = args.to_h['input'].except('clientMutationId') client_mutation_id = args.to_h['input']['clientMutationId'] + # Metaphysics uses camelCase properties and inputs + params = params.transform_keys(&:underscore) + submission = Submission.find_by(id: params['id']) unless submission raise(GraphQL::ExecutionError, 'Submission from ID Not Found') @@ -51,7 +54,7 @@ def self.resolve(_obj, args, context) SubmissionService.update_submission(submission, params.except('id')) OpenStruct.new( - consignment_submission: submission, + consignmentSubmission: submission, client_mutation_id: client_mutation_id ) end diff --git a/app/graph/types/asset_type.rb b/app/graph/types/asset_type.rb index b1bcddbae..6a9dd9883 100644 --- a/app/graph/types/asset_type.rb +++ b/app/graph/types/asset_type.rb @@ -10,5 +10,6 @@ module Types field :asset_type, !types.String, 'type of this Asset' field :gemini_token, types.String, 'gemini token for asset' field :submission_id, !types.ID + field :submissionID, !types.ID, property: :submission_id # Alias for MPv2 compatability end end diff --git a/app/graph/types/mutation_type.rb b/app/graph/types/mutation_type.rb index 04f4c14af..a474da1a2 100644 --- a/app/graph/types/mutation_type.rb +++ b/app/graph/types/mutation_type.rb @@ -7,13 +7,13 @@ module Types description 'Mutation root for this schema' field :createConsignmentSubmission, - Mutations::CreateConsignmentSubmission::Definition.return_type do + Mutations::CreateSubmissionMutation::Definition.return_type do permit :user argument :input, - Mutations::CreateConsignmentSubmission::Definition.input_type + Mutations::CreateSubmissionMutation::Definition.input_type resolve lambda { |obj, args, context| - Mutations::CreateConsignmentSubmission.resolve( + Mutations::CreateSubmissionMutation.resolve( obj, args, context @@ -22,13 +22,13 @@ module Types end field :updateConsignmentSubmission, - Mutations::UpdateConsignmentSubmission::Definition.return_type do + Mutations::UpdateSubmissionMutation::Definition.return_type do permit :user argument :input, - Mutations::UpdateConsignmentSubmission::Definition.input_type + Mutations::UpdateSubmissionMutation::Definition.input_type resolve lambda { |obj, args, context| - Mutations::UpdateConsignmentSubmission.resolve( + Mutations::UpdateSubmissionMutation.resolve( obj, args, context diff --git a/app/graph/types/submission_type.rb b/app/graph/types/submission_type.rb index 859558f8b..ef1c0b24a 100644 --- a/app/graph/types/submission_type.rb +++ b/app/graph/types/submission_type.rb @@ -7,6 +7,7 @@ module Types description 'Consignment Submission' field :id, !types.ID, 'Uniq ID for this submission' + field :internalID, types.ID, property: :id # Alias for MPv2 compatability field :additional_info, types.String field :user_id, !types.String field :artist_id, !types.String