wallet screen

This commit is contained in:
João Geonizeli
2021-08-11 20:51:42 -03:00
parent 38b60ca0fa
commit a057931c51
19 changed files with 656 additions and 20 deletions

View 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

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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