Class: GraphQL::Query::ValidationPipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/validation_pipeline.rb

Overview

Contain the validation pipeline and expose the results.

  1. Checks in the GraphQL::Query constructor:
- Rescue a ParseError, halt if there is one
- Check for selected operation, halt if not found
  1. Validate the AST, halt if errors
  2. Validate the variables, halt if errors
  3. Run query analyzers, halt if errors

valid? is false if any of the above checks halted the pipeline.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, parse_error:, operation_name_error:, max_depth:, max_complexity:) ⇒ ValidationPipeline

Returns a new instance of ValidationPipeline.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql/query/validation_pipeline.rb', line 20

def initialize(query:, parse_error:, operation_name_error:, max_depth:, max_complexity:)
  @validation_errors = []
  @parse_error = parse_error
  @operation_name_error = operation_name_error
  @query = query
  @schema = query.schema
  @max_depth = max_depth
  @max_complexity = max_complexity

  @has_validated = false
end

Instance Attribute Details

#max_complexity ⇒ Object (readonly)

:nodoc:



18
19
20
# File 'lib/graphql/query/validation_pipeline.rb', line 18

def max_complexity
  @max_complexity
end

#max_depth ⇒ Object (readonly)

:nodoc:



18
19
20
# File 'lib/graphql/query/validation_pipeline.rb', line 18

def max_depth
  @max_depth
end

#validate_timeout_remaining ⇒ Object (readonly)

:nodoc:



18
19
20
# File 'lib/graphql/query/validation_pipeline.rb', line 18

def validate_timeout_remaining
  @validate_timeout_remaining
end

Instance Method Details

#analyzers ⇒ Object



54
55
56
57
# File 'lib/graphql/query/validation_pipeline.rb', line 54

def analyzers
  ensure_has_validated
  @query_analyzers
end

#has_validated? ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/graphql/query/validation_pipeline.rb', line 59

def has_validated?
  @has_validated == true
end

#valid? ⇒ Boolean

Returns

  • Boolean — does this query have errors that should prevent it from running?

:call-seq:

valid?() -> bool

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/graphql/query/validation_pipeline.rb', line 38

def valid?
  ensure_has_validated
  @valid
end

#validation_errors ⇒ Object

Returns

  • Array<GraphQL::StaticValidation::Error, GraphQL::Query::VariableValidationError> — Static validation errors for the query string

:call-seq:

validation_errors() -> Array[GraphQL::StaticValidation::Error | GraphQL::Query::VariableValidationError]


49
50
51
52
# File 'lib/graphql/query/validation_pipeline.rb', line 49

def validation_errors
  ensure_has_validated
  @validation_errors
end