ibrain-core 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c262993dec17ae9595461851704d63d2db7c281c131e54694f804d935a2554e
4
- data.tar.gz: 8a1500b6a3dc0e6ab6411335f85c7f5e197fb4f4166e87bf301c3c50a48611d8
3
+ metadata.gz: 0accd0585dbb8b751342cfbeae014e22ef41b75b56bb3aba37f2071813307344
4
+ data.tar.gz: b5e922dea8ec2515d5ee390271d04e9ba879d88d0b629f54868420d46771386e
5
5
  SHA512:
6
- metadata.gz: e26db7af8481c6910d5a77a65c0c199da2464302ce412cbf13d682c25cfeac8d9fe15e27eb11def778b4ead1cd40cdb2060d76a9967f9a21f39c44711ce5acb4
7
- data.tar.gz: 7b7681cc908112ae19e63e3abbec85824f86331ea91f966953b744f15564cac62f087a31b234dd4b4888cd62a2b5b8300b93546cf7d9ad9dae2ca75b55475ae6
6
+ metadata.gz: be6f2b3e72bdba22100743dfa74b99b001ab17f5c4ebf3cc4218ab776667fc3761ad7db01326de8ed4c0d9cf5362f35cf66bbde2260fc943e72327e81a8557b0
7
+ data.tar.gz: 47dd41b984584ca4e3bc820e9a07b18eafcbcd8312f5ccad9c03c322ca49ff56cc2bf43ac1d1360db61f87dca904cfb61edac157b6527ae94ce746e1224a2abf
@@ -13,14 +13,6 @@ module Ibrain
13
13
 
14
14
  protected
15
15
 
16
- def operation_name
17
- params[:operationName]
18
- end
19
-
20
- def skip_operations
21
- super || ['IntrospectionQuery'].include?(operation_name)
22
- end
23
-
24
16
  def cryptor
25
17
  Ibrain::Encryptor.new
26
18
  end
@@ -5,7 +5,6 @@ module Ibrain
5
5
  class GraphqlController < ::Ibrain::BaseController
6
6
  include Devise::Controllers::ScopedViews
7
7
 
8
- before_action :authenticate_user!, unless: :skip_operations
9
8
  before_action :map_user_class_to_request
10
9
 
11
10
  helpers = %w(resource scope_name resource_name signed_in_resource
@@ -6,7 +6,7 @@ module Ibrain
6
6
 
7
7
  use GraphQL::Guard.new(
8
8
  policy_object: ::Ibrain::Config.graphql_policy.safe_constantize,
9
- not_authorized: ->(type, field) { raise IbrainErrors::UnknownError.new("Not authorized to access #{type}.#{field}") }
9
+ not_authorized: ->(type, field) { raise IbrainErrors::PermissionError.new("You not have permission to access #{type}.#{field}") }
10
10
  )
11
11
 
12
12
  # Union and Interface Resolution
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Extentions
5
+ class SessionRequired < GraphQL::Schema::FieldExtension
6
+ def resolve(object:, arguments:, **rest)
7
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.session.invalid_session') if is_invalid_session(object)
8
+
9
+ # yield the current time as `memo`
10
+ yield(object, arguments, rest)
11
+ end
12
+
13
+ private
14
+
15
+ def is_invalid_session(object)
16
+ object.try(:contect).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiConnection < Types::BaseObject
6
+ # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
7
+ include GraphQL::Types::Relay::ConnectionBehaviors
8
+
9
+ field :total_count, Integer, null: false, camelize: false
10
+
11
+ def total_count
12
+ object.items.size
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiEdge < Types::BaseObject
6
+ # add `node` and `cursor` fields, as well as `node_type(...)` override
7
+ include GraphQL::Types::Relay::EdgeBehaviors
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiField < GraphQL::Schema::Field
6
+ argument_class ::Ibrain::Types::BaseArgument
7
+
8
+ def initialize(*args, session_required: true, **kwargs, &block)
9
+ super(*args, camelize: false, **kwargs, &block)
10
+
11
+ extension(Ibrain::Extentions::SessionRequired, session_required: session_required) if session_required
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiObject < GraphQL::Schema::Object
6
+ include GraphQL::Relay::Node
7
+
8
+ edge_type_class(Ibrain::Types::BaseApiEdge)
9
+ connection_type_class(Ibrain::Types::BaseApiConnection)
10
+
11
+ field_class Ibrain::Types::BaseApiField
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class MutationType < Ibrain::Types::BaseObject
4
+ class MutationType < Ibrain::Types::BaseApiObject
5
5
  description 'Define all mutation for client'
6
6
 
7
7
  # TODO: remove me
8
- field :test_field, String, null: false,
8
+ # Default session_required is true, set false if yout want to skip authenticated
9
+ field :test_authenticated_field, , String, null: false,
9
10
  description: 'An example field added by the generator'
11
+
12
+ field :test_field, String, null: false,
13
+ description: 'An example field added by the generator', session_required: false
10
14
  def test_field
11
15
  'Hello World'
12
16
  end
17
+
18
+ def test_authenticated_field
19
+ 'Im logged in!'
20
+ end
13
21
  end
14
22
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class QueryType < Ibrain::Types::BaseObject
4
+ class QueryType < Ibrain::Types::BaseApiObject
5
5
  description 'Define all resolver for client'
6
6
 
7
7
  # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
@@ -9,9 +9,11 @@ module Types
9
9
  include GraphQL::Types::Relay::HasNodesField
10
10
 
11
11
  # Add root-level fields here.
12
+ # Default session_required is true, set false if yout want to skip authenticated
12
13
  # They will be entry points for queries on your schema.
13
14
 
14
15
  # Example with user resolvers
15
- # field :users, resolver: Resolvers::UsersResolver
16
+ # field :authenticated_users, resolver: Resolvers::UsersResolver
17
+ # field :users, resolver: Resolvers::UsersResolver, session_required: false
16
18
  end
17
19
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
8
8
  end
9
9
 
10
10
  def self.previous_ibrain_minor_version
11
- '0.2.0'
11
+ '0.2.1'
12
12
  end
13
13
 
14
14
  def self.ibrain_gem_version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -186,6 +186,7 @@ files:
186
186
  - app/controllers/ibrain/core/graphql_controller.rb
187
187
  - app/graphql/ibrain/base_schema.rb
188
188
  - app/graphql/ibrain/extentions/default_value.rb
189
+ - app/graphql/ibrain/extentions/session_required.rb
189
190
  - app/graphql/ibrain/interfaces/base_interface.rb
190
191
  - app/graphql/ibrain/interfaces/person_interface.rb
191
192
  - app/graphql/ibrain/interfaces/record_interface.rb
@@ -198,6 +199,10 @@ files:
198
199
  - app/graphql/ibrain/resolvers/base_resolver.rb
199
200
  - app/graphql/ibrain/types/aggregate_type.rb
200
201
  - app/graphql/ibrain/types/attribute_type.rb
202
+ - app/graphql/ibrain/types/base_api_connection.rb
203
+ - app/graphql/ibrain/types/base_api_edge.rb
204
+ - app/graphql/ibrain/types/base_api_field.rb
205
+ - app/graphql/ibrain/types/base_api_object.rb
201
206
  - app/graphql/ibrain/types/base_argument.rb
202
207
  - app/graphql/ibrain/types/base_connection.rb
203
208
  - app/graphql/ibrain/types/base_edge.rb
@@ -207,7 +212,6 @@ files:
207
212
  - app/graphql/ibrain/types/base_interface.rb
208
213
  - app/graphql/ibrain/types/base_node.rb
209
214
  - app/graphql/ibrain/types/base_object.rb
210
- - app/graphql/ibrain/types/base_query_type.rb
211
215
  - app/graphql/ibrain/types/base_scalar.rb
212
216
  - app/graphql/ibrain/types/base_union.rb
213
217
  - app/graphql/ibrain/types/filter_type.rb
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Types
5
- class BaseQueryType < Types::BaseObject
6
- # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
7
- include GraphQL::Types::Relay::HasNodeField
8
- include GraphQL::Types::Relay::HasNodesField
9
-
10
- # Add root-level fields here.
11
- # They will be entry points for queries on your schema.
12
- end
13
- end
14
- end