wallet screen
This commit is contained in:
13
app/graphql/types/balance_type.rb
Normal file
13
app/graphql/types/balance_type.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
module Types
|
||||
class BalanceType < Types::BaseObject
|
||||
implements GraphQL::Types::Relay::Node
|
||||
global_id_field :id
|
||||
|
||||
graphql_name "Balance"
|
||||
|
||||
field :id, ID, null: false
|
||||
field :currency, CurrencyType, null: false
|
||||
field :amount, String, null: false
|
||||
end
|
||||
end
|
||||
12
app/graphql/types/currency_type.rb
Normal file
12
app/graphql/types/currency_type.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
module Types
|
||||
class CurrencyType < Types::BaseObject
|
||||
implements GraphQL::Types::Relay::Node
|
||||
global_id_field :id
|
||||
|
||||
graphql_name "Currency"
|
||||
|
||||
field :id, ID, null: false
|
||||
field :name, String, null: false
|
||||
end
|
||||
end
|
||||
@@ -8,5 +8,10 @@ module Types
|
||||
def current_user
|
||||
context[:current_user]
|
||||
end
|
||||
|
||||
field :balances, BalanceType.connection_type, null: false
|
||||
def balances
|
||||
Pundit.policy_scope(current_user, Balance)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
module Types
|
||||
class UserType < Types::BaseObject
|
||||
# implements GraphQL::Types::Relay::Node
|
||||
|
||||
global_id_field :id
|
||||
|
||||
graphql_name "User"
|
||||
|
||||
field :id, ID, null: false
|
||||
field :first_name, String, null: false
|
||||
field :last_name, String, null: false
|
||||
|
||||
@@ -4,15 +4,22 @@ class XStakeSchema < GraphQL::Schema
|
||||
query(Types::QueryType)
|
||||
|
||||
def self.resolve_type(abstract_type, obj, ctx)
|
||||
raise(GraphQL::RequiredImplementationMissingError)
|
||||
case obj
|
||||
when Currency
|
||||
Types::CurrencyType
|
||||
when Balance
|
||||
Types::BalanceType
|
||||
else
|
||||
raise(GraphQL::RequiredImplementationMissingError, "Unexpected object: #{obj}")
|
||||
end
|
||||
end
|
||||
|
||||
def self.id_from_object(object, type_definition, query_ctx)
|
||||
def self.id_from_object(object, type_definition, ctx)
|
||||
GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
|
||||
end
|
||||
|
||||
def self.object_from_id(id, query_ctx)
|
||||
def self.object_from_id(id, ctx)
|
||||
type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
|
||||
type_name.constantize.find(item_id)
|
||||
Pundit.policy_scope(ctx[:current_user], type_name.constantize).find(item_id)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user