Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stitching] Ensure schema matches existing MPv2 definitions #504

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@damassi damassi Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graphql-ruby has a nice (or rather, confusing) feature where it will automatically take snake_case fields and camelize them (convenient for MPv2). However, this doesn't apply to inputs.

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 @@ -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')
Copy link
Member Author

@damassi damassi Mar 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whats up here, but Rails will reject a submission if this property is included, only a naked numeric value seems to be used in the UI.


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
24 changes: 12 additions & 12 deletions spec/requests/api/graphql/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@
<<-GRAPHQL
mutation {
createConsignmentSubmission(input: { title: "soup" }){
consignment_submission {
consignmentSubmission {
id
title
}
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions spec/requests/api/graphql/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down