Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rufo in GraphQL-Ruby #1800

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 2 additions & 4 deletions benchmark/run.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true
require "dummy/schema"
require "benchmark/ips"
require 'ruby-prof'
require 'memory_profiler'
require "ruby-prof"
require "memory_profiler"

module GraphQLBenchmark
QUERY_STRING = GraphQL::Introspection::INTROSPECTION_QUERY
Expand All @@ -14,13 +14,11 @@ module GraphQLBenchmark
ABSTRACT_FRAGMENTS = GraphQL.parse(File.read(File.join(BENCHMARK_PATH, "abstract_fragments.graphql")))
ABSTRACT_FRAGMENTS_2 = GraphQL.parse(File.read(File.join(BENCHMARK_PATH, "abstract_fragments_2.graphql")))


BIG_SCHEMA = GraphQL::Schema.from_definition(File.join(BENCHMARK_PATH, "big_schema.graphql"))
BIG_QUERY = GraphQL.parse(File.read(File.join(BENCHMARK_PATH, "big_query.graphql")))

module_function
def self.run(task)

Benchmark.ips do |x|
case task
when "query"
Expand Down
11 changes: 5 additions & 6 deletions guides/_plugins/api_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def api_doc(input)
end

doc_path = ruby_ident
.gsub("::", "/") # namespaces
.sub(/#(.+)$/, "#\\1-instance_method") # instance methods
.gsub("::", "/") # namespaces
.sub(/#(.+)$/, "#\\1-instance_method") # instance methods
.sub(/\.(.+)$/, "#\\1-class_method") # class methods

%|<a href="#{API_DOC_ROOT}#{doc_path}" target="_blank" title="API docs for #{ruby_ident}"><code>#{input}</code></a>|
Expand Down Expand Up @@ -75,7 +75,7 @@ def initialize(tag_name, guide_info, tokens)

def render(context)
<<~HTML.chomp
<a href="#{context["site"]["baseurl"]}/#{@path}">#{@text}</a>
<a href="#{context["site"]["baseurl"]}/#{@path}">#{@text}</a>
HTML
end

Expand All @@ -86,16 +86,15 @@ def strip_arg(text)
end

POSSIBLE_EXTENSIONS = [".html", ".md"]

def exist?(path)
filepath = GUIDES_ROOT + path.split("#").first
filepath = GUIDES_ROOT + path.split("#").first
filepath = filepath.sub(".html", "")
POSSIBLE_EXTENSIONS.any? { |ext| File.exist?(filepath + ext) }
end
end
end



Liquid::Template.register_filter(GraphQLSite::APIDoc)
Liquid::Template.register_tag("api_doc_root", GraphQLSite::APIDocRoot)
Liquid::Template.register_tag("open_an_issue", GraphQLSite::OpenAnIssue)
Expand Down
34 changes: 17 additions & 17 deletions guides/_tasks/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
task serve: [:build_doc] do
require "jekyll"
options = {
"source" => File.expand_path("guides"),
"source" => File.expand_path("guides"),
"destination" => File.expand_path("guides/_site"),
"watch" => true,
"serving" => true
"watch" => true,
"serving" => true,
}
# Generate the site in server mode.
puts "Running Jekyll..."
Expand All @@ -64,11 +64,11 @@
# Proceed to purge all files in case we removed a file in this release.
puts "Cleaning gh-pages directory..."
purge_exclude = [
'gh-pages/.',
'gh-pages/..',
'gh-pages/.git',
'gh-pages/.gitignore',
'gh-pages/api-doc',
"gh-pages/.",
"gh-pages/..",
"gh-pages/.git",
"gh-pages/.gitignore",
"gh-pages/api-doc",
]

FileList["gh-pages/{*,.*}"].exclude(*purge_exclude).each do |path|
Expand All @@ -77,25 +77,25 @@

# Copy site to gh-pages dir.
puts "Building site into gh-pages branch..."
ENV['JEKYLL_ENV'] = 'production'
ENV["JEKYLL_ENV"] = "production"
require "jekyll"
Jekyll::Commands::Build.process({
"source" => File.expand_path("guides"),
"destination" => File.expand_path("gh-pages"),
"sass" => { "style" => "compressed" }
"source" => File.expand_path("guides"),
"destination" => File.expand_path("gh-pages"),
"sass" => {"style" => "compressed"},
})

File.write('gh-pages/.nojekyll', "Prevent GitHub from running Jekyll")
File.write("gh-pages/.nojekyll", "Prevent GitHub from running Jekyll")

# Commit and push.
puts "Committing and pushing to GitHub Pages..."
sha = `git rev-parse HEAD`.strip
Dir.chdir('gh-pages') do
Dir.chdir("gh-pages") do
sh "git add ."
sh "git commit --allow-empty -m 'Updating to #{sha}.'"
sh "git push origin gh-pages"
end
puts 'Done.'
puts "Done."
end

YARD::Rake::YardocTask.new(:prepare_yardoc)
Expand All @@ -105,8 +105,8 @@

def to_rubydoc_url(path)
"/api-doc/#{GraphQL::VERSION}/" + path
.gsub("::", "/") # namespaces
.sub(/#(.+)$/, "#\\1-instance_method") # instance methods
.gsub("::", "/") # namespaces
.sub(/#(.+)$/, "#\\1-instance_method") # instance methods
.sub(/\.(.+)$/, "#\\1-class_method") # class methods
end

Expand Down
8 changes: 4 additions & 4 deletions lib/generators/graphql/core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'rails/generators/base'
require "rails/generators/base"

module Graphql
module Generators
Expand All @@ -10,7 +10,7 @@ def self.included(base)
:directory,
type: :string,
default: "app/graphql",
desc: "Directory where generated files should be saved"
desc: "Directory where generated files should be saved",
)
end

Expand All @@ -25,8 +25,8 @@ def insert_root_type(type, name)

def create_mutation_root_type
create_dir("#{options[:directory]}/mutations")
template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
insert_root_type('mutation', 'MutationType')
template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", {skip: true})
insert_root_type("mutation", "MutationType")
end

def schema_file_path
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/graphql/enum_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'generators/graphql/type_generator'
require "generators/graphql/type_generator"

module Graphql
module Generators
Expand All @@ -11,7 +11,7 @@ module Generators
# ```
class EnumGenerator < TypeGeneratorBase
desc "Create a GraphQL::EnumType with the given name and values"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

argument :values,
type: :array,
Expand Down
10 changes: 5 additions & 5 deletions lib/generators/graphql/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'rails/generators/base'
require_relative 'core'
require "rails/generators/base"
require_relative "core"

module Graphql
module Generators
Expand Down Expand Up @@ -51,7 +51,7 @@ class InstallGenerator < Rails::Generators::Base
include Core

desc "Install GraphQL folder structure and boilerplate code"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

class_option :schema,
type: :string,
Expand Down Expand Up @@ -98,7 +98,7 @@ def create_folder_structure

# Note: You can't have a schema without the query type, otherwise introspection breaks
template("query_type.erb", "#{options[:directory]}/types/query_type.rb")
insert_root_type('query', 'QueryType')
insert_root_type("query", "QueryType")

create_mutation_root_type unless options.skip_mutation_root_type?

Expand All @@ -117,7 +117,7 @@ def create_folder_structure
gem("graphiql-rails", group: :development)

# This is a little cheat just to get cleaner shell output:
log :route, 'graphiql-rails'
log :route, "graphiql-rails"
shell.mute do
# Rails 5.2 has better support for `route`?
if Rails::VERSION::STRING > "5.2"
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/graphql/interface_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'generators/graphql/type_generator'
require "generators/graphql/type_generator"

module Graphql
module Generators
Expand All @@ -11,7 +11,7 @@ module Generators
# ```
class InterfaceGenerator < TypeGeneratorBase
desc "Create a GraphQL::InterfaceType with the given name and fields"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

argument :fields,
type: :array,
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/graphql/loader_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LoaderGenerator < Rails::Generators::NamedBase
include Core

desc "Create a GraphQL::Batch::Loader by name"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

def create_loader_file
template "loader.erb", "#{options[:directory]}/loaders/#{file_path}.rb"
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/graphql/mutation_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'rails/generators/named_base'
require_relative 'core'
require "rails/generators/named_base"
require_relative "core"

module Graphql
module Generators
Expand All @@ -12,7 +12,7 @@ class MutationGenerator < Rails::Generators::Base
include Core

desc "Create a Relay Classic mutation by name"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

argument :name, type: :string

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/graphql/object_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'generators/graphql/type_generator'
require "generators/graphql/type_generator"

module Graphql
module Generators
Expand All @@ -13,7 +13,7 @@ module Generators
# Add the Node interface with `--node`.
class ObjectGenerator < TypeGeneratorBase
desc "Create a GraphQL::ObjectType with the given name and fields"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

argument :fields,
type: :array,
Expand Down
10 changes: 5 additions & 5 deletions lib/generators/graphql/type_generator.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true
require 'rails/generators/base'
require 'graphql'
require 'active_support'
require 'active_support/core_ext/string/inflections'
require_relative 'core'
require "rails/generators/base"
require "graphql"
require "active_support"
require "active_support/core_ext/string/inflections"
require_relative "core"

module Graphql
module Generators
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/graphql/union_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'generators/graphql/type_generator'
require "generators/graphql/type_generator"

module Graphql
module Generators
Expand All @@ -11,7 +11,7 @@ module Generators
# ```
class UnionGenerator < TypeGeneratorBase
desc "Create a GraphQL::UnionType with the given name and possible types"
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("../templates", __FILE__)

argument :possible_types,
type: :array,
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/analysis/analyze_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Analysis

# @return [void]
def analyze_multiplex(multiplex, analyzers)
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do
multiplex.trace("analyze_multiplex", {multiplex: multiplex}) do
reducer_states = analyzers.map { |r| ReducerState.new(r, multiplex) }
query_results = multiplex.queries.map do |query|
if query.valid?
Expand Down Expand Up @@ -38,7 +38,7 @@ def analyze_multiplex(multiplex, analyzers)
# @param analyzers [Array<#call>] Objects that respond to `#call(memo, visit_type, irep_node)`
# @return [Array<Any>] Results from those analyzers
def analyze_query(query, analyzers, multiplex_states: [])
query.trace("analyze_query", { query: query }) do
query.trace("analyze_query", {query: query}) do
analyzers_to_run = analyzers.select do |analyzer|
if analyzer.respond_to?(:analyze?)
analyzer.analyze?(query)
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/analysis/field_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initial_value(query)
{
query: query,
used_fields: Set.new,
used_deprecated_fields: Set.new
used_deprecated_fields: Set.new,
}
end

Expand Down
3 changes: 2 additions & 1 deletion lib/graphql/analysis/max_query_complexity.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require_relative "./query_complexity"

module GraphQL
module Analysis
# Used under the hood to implement complexity validation,
Expand All @@ -12,7 +13,7 @@ module Analysis
#
class MaxQueryComplexity < GraphQL::Analysis::QueryComplexity
def initialize(max_complexity)
disallow_excessive_complexity = ->(query, 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
Expand Down
3 changes: 2 additions & 1 deletion lib/graphql/analysis/max_query_depth.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require_relative "./query_depth"

module GraphQL
module Analysis
# Used under the hood to implement depth validation,
Expand All @@ -12,7 +13,7 @@ module Analysis
#
class MaxQueryDepth < GraphQL::Analysis::QueryDepth
def initialize(max_depth)
disallow_excessive_depth = ->(query, depth) {
disallow_excessive_depth = -> (query, depth) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The no-space Procs were originially introduced because someone wanted to support Ruby 1.9. AFAIK they gave up, and don't actually use GraphQL-Ruby after all. So this will be a big change, but probably OK.

if depth > max_depth
GraphQL::AnalysisError.new("Query has depth of #{depth}, which exceeds max depth of #{max_depth}")
else
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(fields:, irep_nodes:, context:)

module Analyzer
module_function

def initial_value(query)
{
schema: query.schema,
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "graphql/backtrace/table"
require "graphql/backtrace/traced_error"
require "graphql/backtrace/tracer"

module GraphQL
# Wrap unhandled errors with {TracedError}.
#
Expand Down
Loading