Class: GraphQL::Schema::Directive::Feature
- Inherits:
-
GraphQL::Schema::Directive
- Object
- Member
- GraphQL::Schema::Directive
- GraphQL::Schema::Directive::Feature
- Defined in:
- lib/graphql/schema/directive/feature.rb
Overview
An example directive to show how you might interact with the runtime.
This directive might be used along with a server-side feature flag system like Flipper.
With that system, you could use this directive to exclude parts of a query if the current viewer doesn't have certain flags enabled. (So, this flag would be for internal clients, like your iOS app, not third-party API clients.)
To use it, you have to implement .enabled?
, for example:
Constant Summary
Constants inherited from GraphQL::Schema::Directive
DEFAULT_DEPRECATION_REASON, LOCATIONS, LOCATION_DESCRIPTIONS
Constants included from Member::HasArguments
Member::HasArguments::NO_ARGUMENTS
Constants included from Member::HasDirectives
Member::HasDirectives::NO_DIRECTIVES
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Instance Attribute Summary
Attributes inherited from GraphQL::Schema::Directive
Class Method Summary collapse
-
.enabled?(flag_name, object, context) ⇒ Boolean
Override this method in your app's subclass of this directive.
-
.include?(object, arguments, context) ⇒ Boolean
Implement the Directive API.
Methods inherited from GraphQL::Schema::Directive
default_directive, default_directive?, default_graphql_name, #initialize, locations, on_field?, on_fragment?, on_operation?, path, resolve, static_include?, to_graphql
Methods included from Member::HasArguments
#add_argument, #all_argument_definitions, #argument, #argument_class, #arguments, #arguments_statically_coercible?, #coerce_arguments, #get_argument, #own_arguments, #validate_directive_argument
Methods included from Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy, #type_class
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Member::BaseDSLMethods
#accessible?, #authorized?, #default_graphql_name, #description, #graphql_name, #introspection, #introspection?, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?
Methods included from Member::BaseDSLMethods::ConfigurationExtension
Methods included from Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Member::Scoped
Methods included from Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Methods included from Member::HasPath
Methods included from Member::HasAstNode
Methods included from Member::HasDirectives
#directive, #directives, #remove_directive
Constructor Details
This class inherits a constructor from GraphQL::Schema::Directive
Class Method Details
.enabled?(flag_name, object, context) ⇒ Boolean
Override this method in your app's subclass of this directive.
60 61 62 |
# File 'lib/graphql/schema/directive/feature.rb', line 60 def self.enabled?(flag_name, object, context) raise GraphQL::RequiredImplementationMissingError, "Implement `.enabled?(flag_name, object, context)` to return true or false for the feature flag (#{flag_name.inspect})" end |
.include?(object, arguments, context) ⇒ Boolean
Implement the Directive API
49 50 51 52 |
# File 'lib/graphql/schema/directive/feature.rb', line 49 def self.include?(object, arguments, context) flag_name = arguments[:flag] self.enabled?(flag_name, object, context) end |