Add Api::V2::Schema
This commit is contained in:
parent
2e854f2ac3
commit
d2fdaacb5d
3 changed files with 29 additions and 1 deletions
26
app/graphql/api/v2/schema.rb
Normal file
26
app/graphql/api/v2/schema.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class Api::V2::Schema < GraphQL::Schema
|
||||
default_max_page_size 100
|
||||
max_complexity 300
|
||||
max_depth 15
|
||||
|
||||
def self.unauthorized_object(error)
|
||||
# Add a top-level error to the response instead of returning nil:
|
||||
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })
|
||||
end
|
||||
|
||||
middleware(GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 5) do |_, query|
|
||||
Rails.logger.info("GraphQL Timeout: #{query.query_string}")
|
||||
end)
|
||||
|
||||
if Rails.env.development?
|
||||
query_analyzer(GraphQL::Analysis::QueryComplexity.new do |_, complexity|
|
||||
Rails.logger.info("[GraphQL Query Complexity] #{complexity}")
|
||||
end)
|
||||
query_analyzer(GraphQL::Analysis::QueryDepth.new do |_, depth|
|
||||
Rails.logger.info("[GraphQL Query Depth] #{depth}")
|
||||
end)
|
||||
end
|
||||
|
||||
use GraphQL::Batch
|
||||
use GraphQL::Tracing::SkylightTracing
|
||||
end
|
2
lib/tasks/graphql.rake
Normal file
2
lib/tasks/graphql.rake
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "graphql/rake_task"
|
||||
GraphQL::RakeTask.new(schema_name: "Api::V2::Schema", directory: 'app/graphql')
|
|
@ -45,7 +45,7 @@
|
|||
"webpack-dev-server": "^3.7.2"
|
||||
},
|
||||
"scripts": {
|
||||
"lint:ec": "eclint check $({ git ls-files ; find vendor -type f ; echo 'db/schema.rb' ; } | sort | uniq -u)",
|
||||
"lint:ec": "eclint check $({ git ls-files | grep -v app/graphql/schema.graphql ; find vendor -type f ; echo 'db/schema.rb' ; } | sort | uniq -u)",
|
||||
"lint:js": "eslint ./app/javascript ./app/assets/javascripts ./config/webpack"
|
||||
},
|
||||
"engines": {
|
||||
|
|
Loading…
Add table
Reference in a new issue