From 7e08ea99521202c5c55da5581a9a988258a46d1a Mon Sep 17 00:00:00 2001 From: Christopher Pappas Date: Wed, 4 Mar 2020 21:29:47 -0800 Subject: [PATCH 1/2] [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} | 34 +++++++++++-------- app/graph/types/asset_type.rb | 1 + app/graph/types/mutation_type.rb | 12 +++---- app/graph/types/submission_type.rb | 1 + 6 files changed, 55 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} (62%) diff --git a/app/graph/mutations/add_asset_to_consignment_submission.rb b/app/graph/mutations/add_asset_to_consignment_submission.rb index e826bb56..e70826b2 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 acd11c7f..8f2aabc5 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 62% rename from app/graph/mutations/update_consignment_submission.rb rename to app/graph/mutations/update_submission_mutation.rb index 888b3597..95f2392b 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') @@ -49,9 +52,12 @@ def self.resolve(_obj, args, context) raise(GraphQL::ExecutionError, 'Submission Not Found') end + # FIXME: Why does the API reject this property? + params.delete('dimensions_metric') + 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 b1bcddba..752e7d07 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 04f4c14a..a474da1a 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 859558f8..ef1c0b24 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 From 03ca14bcc47498d2bca765503f453eeab13b4cd5 Mon Sep 17 00:00:00 2001 From: Christopher Pappas Date: Thu, 5 Mar 2020 13:01:12 -0800 Subject: [PATCH 2/2] [Graphql] Fix failing tests --- spec/requests/api/graphql/create_spec.rb | 24 ++++++++++++------------ spec/requests/api/graphql/update_spec.rb | 18 +++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/requests/api/graphql/create_spec.rb b/spec/requests/api/graphql/create_spec.rb index 8d789eef..64926897 100644 --- a/spec/requests/api/graphql/create_spec.rb +++ b/spec/requests/api/graphql/create_spec.rb @@ -15,9 +15,9 @@ let(:create_mutation) do <<-GRAPHQL mutation { - createConsignmentSubmission(input: { state: REJECTED, clientMutationId: "2", artist_id: "andy", title: "soup", category: JEWELRY, minimum_price_dollars: 50000, currency: "GBP" }){ + createConsignmentSubmission(input: { state: REJECTED, clientMutationId: "2", artistID: "andy", title: "soup", category: JEWELRY, minimumPriceDollars: 50000, currency: "GBP" }){ clientMutationId - consignment_submission { + consignmentSubmission { id title category @@ -34,7 +34,7 @@ <<-GRAPHQL mutation { createConsignmentSubmission(input: { title: "soup" }){ - consignment_submission { + consignmentSubmission { id title } @@ -90,32 +90,32 @@ expect(response.status).to eq 200 body = JSON.parse(response.body) expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'id' ] ).not_to be_nil expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'title' ] ).to eq 'soup' expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'category' ] ).to eq 'JEWELRY' expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'state' ] ).to eq 'REJECTED' expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'minimum_price_dollars' ] ).to eq 50_000 expect( - body['data']['createConsignmentSubmission']['consignment_submission'][ + body['data']['createConsignmentSubmission']['consignmentSubmission'][ 'currency' ] ).to eq 'GBP' @@ -135,9 +135,9 @@ create_asset = <<-GRAPHQL mutation { - addAssetToConsignmentSubmission(input: { clientMutationId: "test", submission_id: #{ + addAssetToConsignmentSubmission(input: { clientMutationId: "test", submissionID: #{ submission.id - }, gemini_token: "gemini-token-hash" }){ + }, geminiToken: "gemini-token-hash" }){ clientMutationId asset { id @@ -150,7 +150,7 @@ post '/api/graphql', params: { query: create_asset }, headers: headers expect(response.status).to eq 200 - body = JSON.parse(response.body) + body = JSON.parse(response.body) # byebug expect( body['data']['addAssetToConsignmentSubmission']['asset']['id'] ).not_to be_nil diff --git a/spec/requests/api/graphql/update_spec.rb b/spec/requests/api/graphql/update_spec.rb index 5b529d24..23883604 100644 --- a/spec/requests/api/graphql/update_spec.rb +++ b/spec/requests/api/graphql/update_spec.rb @@ -26,9 +26,9 @@ mutation { updateConsignmentSubmission(input: { state: DRAFT, category: JEWELRY, clientMutationId: "test", id: #{ submission.id - }, artist_id: "andy-warhol", title: "soup" }){ + }, artistID: "andy-warhol", title: "soup" }){ clientMutationId - consignment_submission { + consignmentSubmission { category state id @@ -43,9 +43,9 @@ let(:update_mutation_random_id) do <<-GRAPHQL mutation { - updateConsignmentSubmission(input: { clientMutationId: "test", id: 999999, artist_id: "andy-warhol", title: "soup" }){ + updateConsignmentSubmission(input: { clientMutationId: "test", id: 999999, artistID: "andy-warhol", title: "soup" }){ clientMutationId - consignment_submission { + consignmentSubmission { id artist_id title @@ -114,28 +114,28 @@ expect(response.status).to eq 200 body = JSON.parse(response.body) expect( - body['data']['updateConsignmentSubmission']['consignment_submission'][ + body['data']['updateConsignmentSubmission']['consignmentSubmission'][ 'id' ] .to_i ).to eq submission.id expect( - body['data']['updateConsignmentSubmission']['consignment_submission'][ + body['data']['updateConsignmentSubmission']['consignmentSubmission'][ 'title' ] ).to eq 'soup' expect( - body['data']['updateConsignmentSubmission']['consignment_submission'][ + body['data']['updateConsignmentSubmission']['consignmentSubmission'][ 'artist_id' ] ).to eq 'andy-warhol' expect( - body['data']['updateConsignmentSubmission']['consignment_submission'][ + body['data']['updateConsignmentSubmission']['consignmentSubmission'][ 'category' ] ).to eq 'JEWELRY' expect( - body['data']['updateConsignmentSubmission']['consignment_submission'][ + body['data']['updateConsignmentSubmission']['consignmentSubmission'][ 'state' ] ).to eq 'DRAFT'