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

feat: Update GraphQL schema to create or update charges #405

Merged
merged 1 commit into from
Aug 26, 2022
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
6 changes: 6 additions & 0 deletions app/graphql/concerns/charge_model_attributes_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module ChargeModelAttributesHandler
# - Graduated model relies on the the list of `GraduatedRange`
# - Package model has properties `amount_cents`, `package_size` and `free_units`
# - Percentage model has properties `rate`, `fixed_amount`, `free_units_per_events`, `free_units_per_total_aggregation`
# - Volume model has property `ranges` which relies on the list of VolumeRange
def prepare_arguments(arguments)
return arguments if arguments[:charges].blank?

Expand All @@ -31,6 +32,10 @@ def prepare_arguments(arguments)
free_units_per_events: output[:free_units_per_events],
free_units_per_total_aggregation: output[:free_units_per_total_aggregation],
}
when :volume
output[:properties] = {
ranges: output[:volume_ranges],
}
end

# NOTE: delete fields used to build properties
Expand All @@ -42,6 +47,7 @@ def prepare_arguments(arguments)
output.delete(:fixed_amount)
output.delete(:free_units_per_events)
output.delete(:free_units_per_total_aggregation)
output.delete(:volume_ranges)

output
end
Expand Down
3 changes: 3 additions & 0 deletions app/graphql/types/charges/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Input < Types::BaseInputObject
argument :fixed_amount, String, required: false
argument :free_units_per_events, Integer, required: false
argument :free_units_per_total_aggregation, String, required: false

# NOTE: Volume charge model
argument :volume_ranges, [Types::Charges::VolumeRangeInput], required: false
end
end
end
9 changes: 9 additions & 0 deletions app/graphql/types/charges/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Object < Types::BaseObject
field :free_units_per_events, Integer, null: true
field :free_units_per_total_aggregation, String, null: true

# NOTE: Volume charge model
field :volume_ranges, [Types::Charges::VolumeRange], null: true

def amount
return unless object.standard? || object.package?

Expand Down Expand Up @@ -75,6 +78,12 @@ def free_units_per_total_aggregation

object.properties['free_units_per_total_aggregation']
end

def volume_ranges
return unless object.volume?

object.properties['ranges']
end
end
end
end
15 changes: 15 additions & 0 deletions app/graphql/types/charges/volume_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Types
module Charges
class VolumeRange < Types::BaseObject
graphql_name 'VolumeRange'

field :from_value, Integer, null: false
field :to_value, Integer, null: true

field :per_unit_amount, String, null: false
field :flat_amount, String, null: false
end
end
end
15 changes: 15 additions & 0 deletions app/graphql/types/charges/volume_range_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Types
module Charges
class VolumeRangeInput < Types::BaseInputObject
graphql_name 'VolumeRangeInput'

argument :from_value, Integer, required: true
argument :to_value, Integer, required: false

argument :per_unit_amount, String, required: true
argument :flat_amount, String, required: true
end
end
end
16 changes: 16 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type Charge {
packageSize: Int
rate: String
updatedAt: ISO8601DateTime!
volumeRanges: [VolumeRange!]
}

input ChargeInput {
Expand All @@ -161,6 +162,7 @@ input ChargeInput {
id: ID
packageSize: Int
rate: String
volumeRanges: [VolumeRangeInput!]
}

enum ChargeModelEnum {
Expand Down Expand Up @@ -3618,6 +3620,20 @@ type User {
updatedAt: ISO8601DateTime!
}

type VolumeRange {
flatAmount: String!
fromValue: Int!
perUnitAmount: String!
toValue: Int
}

input VolumeRangeInput {
flatAmount: String!
fromValue: Int!
perUnitAmount: String!
toValue: Int
}

type Wallet {
balance: String!
consumedAmount: String!
Expand Down
194 changes: 194 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,28 @@
"deprecationReason": null,
"args": [

]
},
{
"name": "volumeRanges",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "VolumeRange",
"ofType": null
}
}
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
}
],
Expand Down Expand Up @@ -1618,6 +1640,26 @@
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "volumeRanges",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "VolumeRangeInput",
"ofType": null
}
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"enumValues": null
Expand Down Expand Up @@ -13605,6 +13647,158 @@
"inputFields": null,
"enumValues": null
},
{
"kind": "OBJECT",
"name": "VolumeRange",
"description": null,
"interfaces": [

],
"possibleTypes": null,
"fields": [
{
"name": "flatAmount",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
},
{
"name": "fromValue",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
},
{
"name": "perUnitAmount",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
},
{
"name": "toValue",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
}
],
"inputFields": null,
"enumValues": null
},
{
"kind": "INPUT_OBJECT",
"name": "VolumeRangeInput",
"description": null,
"interfaces": null,
"possibleTypes": null,
"fields": null,
"inputFields": [
{
"name": "fromValue",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "toValue",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "perUnitAmount",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "flatAmount",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"enumValues": null
},
{
"kind": "OBJECT",
"name": "Wallet",
Expand Down
Loading