Skip to content

Commit

Permalink
[Stitching] Ensure schema matches existing MPv2 definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
damassi committed Mar 5, 2020
1 parent 8f7126b commit 75f28bf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 39 deletions.
14 changes: 9 additions & 5 deletions app/graph/mutations/add_asset_to_consignment_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
# 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
input_field :title, types.String
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
# 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
input_field :title, types.String
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')
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/graph/types/asset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions app/graph/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/graph/types/submission_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75f28bf

Please sign in to comment.