Sha256: 3e552014dced1f4a883b11ac272817e1c0dfc19ee2b80653849a5dd9108f270d

Contents?: true

Size: 914 Bytes

Versions: 25

Compression:

Stored size: 914 Bytes

Contents

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

25 entries across 25 versions & 1 rubygems

Version Path
graphql-0.19.3 lib/graphql/analysis/max_query_complexity.rb
graphql-0.19.2 lib/graphql/analysis/max_query_complexity.rb
graphql-0.19.1 lib/graphql/analysis/max_query_complexity.rb
graphql-0.19.0 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.15 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.14 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.13 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.12 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.11 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.10 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.9 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.8 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.7 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.6 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.5 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.4 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.3 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.2 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.1 lib/graphql/analysis/max_query_complexity.rb
graphql-0.18.0 lib/graphql/analysis/max_query_complexity.rb