Class: GraphqlDevise::SchemaPlugin
- Inherits:
-
Object
- Object
- GraphqlDevise::SchemaPlugin
- Defined in:
- lib/graphql_devise/schema_plugin.rb
Constant Summary collapse
- INTROSPECTION_FIELDS =
NOTE: Based on GQL-Ruby docs graphql-ruby.org/schema/introspection.html
['__schema', '__type', '__typename']
- DEFAULT_NOT_AUTHENTICATED =
->(field) { raise AuthenticationError, "#{field} field requires authentication" }
Instance Method Summary collapse
-
#initialize(query: nil, mutation: nil, authenticate_default: true, public_introspection: !Rails.env.production?,, resource_loaders: [], unauthenticated_proc: DEFAULT_NOT_AUTHENTICATED) ⇒ SchemaPlugin
constructor
A new instance of SchemaPlugin.
- #trace(event, trace_data) ⇒ Object
- #use(schema_definition) ⇒ Object
Constructor Details
#initialize(query: nil, mutation: nil, authenticate_default: true, public_introspection: !Rails.env.production?,, resource_loaders: [], unauthenticated_proc: DEFAULT_NOT_AUTHENTICATED) ⇒ SchemaPlugin
Returns a new instance of SchemaPlugin.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/graphql_devise/schema_plugin.rb', line 9 def initialize(query: nil, mutation: nil, authenticate_default: true, public_introspection: !Rails.env.production?, resource_loaders: [], unauthenticated_proc: DEFAULT_NOT_AUTHENTICATED) @query = query @mutation = mutation @resource_loaders = resource_loaders @authenticate_default = authenticate_default @public_introspection = public_introspection @unauthenticated_proc = unauthenticated_proc # Must happen on initialize so operations are loaded before the types are added to the schema on GQL < 1.10 load_fields end |
Instance Method Details
#trace(event, trace_data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql_devise/schema_plugin.rb', line 25 def trace(event, trace_data) # Authenticate only root level queries return yield unless event == 'execute_field' && path(trace_data).count == 1 field = traced_field(trace_data) auth_required = authenticate_option(field, trace_data) context = context_from_data(trace_data) if auth_required && !(public_introspection && introspection_field?(field)) raise_on_missing_resource(context, field, auth_required) end yield end |
#use(schema_definition) ⇒ Object
21 22 23 |
# File 'lib/graphql_devise/schema_plugin.rb', line 21 def use(schema_definition) schema_definition.tracer(self) end |