Sha256: cf64a8b573275c54169273cd924cc942040a321794e348131727b9c436f921b7

Contents?: true

Size: 943 Bytes

Versions: 185

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true
require_relative "./query_complexity"
module GraphQL
  module Analysis
    # Used under the hood to implement complexity validation,
    # see {Schema#max_complexity} and {Query#max_complexity}
    #
    # @example Assert max complexity of 10
    #   # DON'T actually do this, graphql-ruby
    #   # Does this for you based on your `max_complexity` setting
    #   MySchema.query_analyzers << GraphQL::Analysis::MaxQueryComplexity.new(10)
    #
    class MaxQueryComplexity < GraphQL::Analysis::QueryComplexity
      def initialize(max_complexity)
        disallow_excessive_complexity = ->(query, complexity) {
          if complexity > max_complexity
            GraphQL::AnalysisError.new("Query has complexity of #{complexity}, which exceeds max complexity of #{max_complexity}")
          else
            nil
          end
        }
        super(&disallow_excessive_complexity)
      end
    end
  end
end

Version data entries

185 entries across 185 versions & 2 rubygems

Version Path
graphql-1.11.12 lib/graphql/analysis/max_query_complexity.rb
graphql-1.11.11 lib/graphql/analysis/max_query_complexity.rb
graphql-1.12.25 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.24 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.23 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.22 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.21 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.20 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.19 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.18 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.17 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.16 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.15 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.14 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.13 lib/graphql/analysis/max_query_complexity.rb
graphql_cody-1.13.0 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.12 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.11 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.10 lib/graphql/analysis/max_query_complexity.rb
graphql-1.13.9 lib/graphql/analysis/max_query_complexity.rb