Merge pull request #5737 from consuldemocracy/dependabot/bundler/graphql-2.3.18

Bump graphql from 2.0.31 to 2.3.18
This commit is contained in:
Sebastia
2024-11-06 13:48:34 +01:00
committed by GitHub
7 changed files with 45 additions and 47 deletions

View File

@@ -27,7 +27,7 @@ gem "foundation_rails_helper", "~> 4.0.1"
gem "globalize", "~> 6.3.0" gem "globalize", "~> 6.3.0"
gem "globalize-accessors", "~> 0.3.0" gem "globalize-accessors", "~> 0.3.0"
gem "graphiql-rails", "~> 1.8.0" gem "graphiql-rails", "~> 1.8.0"
gem "graphql", "~> 2.0.0" gem "graphql", "~> 2.3.18"
gem "groupdate", "~> 6.5.1" gem "groupdate", "~> 6.5.1"
gem "image_processing", "~> 1.13.0" gem "image_processing", "~> 1.13.0"
gem "invisible_captcha", "~> 2.3.0" gem "invisible_captcha", "~> 2.3.0"

View File

@@ -228,6 +228,7 @@ GEM
faraday-net_http (3.3.0) faraday-net_http (3.3.0)
net-http net-http
ffi (1.17.0) ffi (1.17.0)
fiber-storage (1.0.0)
file_validators (3.0.0) file_validators (3.0.0)
activemodel (>= 3.2) activemodel (>= 3.2)
mime-types (>= 1.0) mime-types (>= 1.0)
@@ -255,8 +256,9 @@ GEM
graphiql-rails (1.8.0) graphiql-rails (1.8.0)
railties railties
sprockets-rails sprockets-rails
graphql (2.0.31) graphql (2.3.18)
base64 base64
fiber-storage
groupdate (6.5.1) groupdate (6.5.1)
activesupport (>= 7) activesupport (>= 7)
gyoku (1.4.0) gyoku (1.4.0)
@@ -740,7 +742,7 @@ DEPENDENCIES
globalize (~> 6.3.0) globalize (~> 6.3.0)
globalize-accessors (~> 0.3.0) globalize-accessors (~> 0.3.0)
graphiql-rails (~> 1.8.0) graphiql-rails (~> 1.8.0)
graphql (~> 2.0.0) graphql (~> 2.3.18)
groupdate (~> 6.5.1) groupdate (~> 6.5.1)
i18n-tasks (~> 0.9.37) i18n-tasks (~> 0.9.37)
image_processing (~> 1.13.0) image_processing (~> 1.13.0)

View File

@@ -2,12 +2,6 @@ require "rails_helper"
# Useful resource: http://graphql.org/learn/serving-over-http/ # Useful resource: http://graphql.org/learn/serving-over-http/
def parser_error_raised?(response)
data_is_empty = response["data"].nil?
error_is_present = (JSON.parse(response.body)["errors"].first["message"] =~ /^Parse error on/)
data_is_empty && error_is_present
end
describe GraphqlController, type: :request do describe GraphqlController, type: :request do
let(:proposal) { create(:proposal) } let(:proposal) { create(:proposal) }
@@ -23,7 +17,8 @@ describe GraphqlController, type: :request do
get "/graphql", params: { query: "Malformed query string" } get "/graphql", params: { query: "Malformed query string" }
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(parser_error_raised?(response)).to be_truthy expect(response.parsed_body["data"]).to be nil
expect(response.parsed_body["errors"]).to be_present
end end
specify "without query string" do specify "without query string" do
@@ -58,7 +53,8 @@ describe GraphqlController, type: :request do
post "/graphql", params: { query: "Malformed query string" }.to_json, headers: json_headers post "/graphql", params: { query: "Malformed query string" }.to_json, headers: json_headers
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(parser_error_raised?(response)).to be_truthy expect(response.parsed_body["data"]).to be nil
expect(response.parsed_body["errors"]).to be_present
end end
it "without query string" do it "without query string" do

View File

@@ -5,18 +5,18 @@ describe Types::QueryType do
let(:proposal) { create(:proposal, author: user) } let(:proposal) { create(:proposal, author: user) }
it "returns fields of Int type" do it "returns fields of Int type" do
response = execute("{ proposal(id: #{proposal.id}) { cached_votes_up } }") response = run_graphql_field("Proposal.cached_votes_up", proposal)
expect(dig(response, "data.proposal.cached_votes_up")).to eq(proposal.cached_votes_up) expect(response).to eq(proposal.cached_votes_up)
end end
it "returns fields of String type" do it "returns fields of String type" do
response = execute("{ proposal(id: #{proposal.id}) { title } }") response = run_graphql_field("Proposal.title", proposal)
expect(dig(response, "data.proposal.title")).to eq(proposal.title) expect(response).to eq(proposal.title)
end end
it "returns belongs_to associations" do it "returns belongs_to associations" do
response = execute("{ proposal(id: #{proposal.id}) { public_author { username } } }") response = run_graphql_field("Proposal.public_author.username", proposal)
expect(dig(response, "data.proposal.public_author.username")).to eq(proposal.public_author.username) expect(response).to eq(proposal.public_author.username)
end end
it "returns has_many associations" do it "returns has_many associations" do
@@ -32,36 +32,46 @@ describe Types::QueryType do
end end
it "hides confidential fields of Int type" do it "hides confidential fields of Int type" do
response = execute("{ user(id: #{user.id}) { failed_census_calls_count } }") expect do
expect(hidden_field?(response, "failed_census_calls_count")).to be_truthy run_graphql_field("User.failed_census_calls_count", user)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError
end end
it "hides confidential fields of String type" do it "hides confidential fields of String type" do
response = execute("{ user(id: #{user.id}) { encrypted_password } }") expect do
expect(hidden_field?(response, "encrypted_password")).to be_truthy run_graphql_field("User.encrypted_password", user)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError
end end
it "hides confidential has_one associations" do it "hides confidential has_one associations" do
user.administrator = create(:administrator) user.administrator = create(:administrator)
response = execute("{ user(id: #{user.id}) { administrator { id } } }")
expect(hidden_field?(response, "administrator")).to be_truthy expect do
run_graphql_field("User.administrator.id", user)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError, /no field named `administrator`/
end end
it "hides confidential belongs_to associations" do it "hides confidential belongs_to associations" do
create(:failed_census_call, user: user) user.geozone = create(:geozone)
response = execute("{ user(id: #{user.id}) { failed_census_calls { id } } }")
expect(hidden_field?(response, "failed_census_calls")).to be_truthy expect do
run_graphql_field("User.geozone.id", user)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError, /no field named `geozone`/
end end
it "hides confidential has_many associations" do it "hides confidential has_many associations" do
create(:direct_message, sender: user) create(:direct_message, sender: user)
response = execute("{ user(id: #{user.id}) { direct_messages_sent { id } } }")
expect(hidden_field?(response, "direct_messages_sent")).to be_truthy expect do
run_graphql_field("User.direct_messages_sent.id", user)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError,
/no field named `direct_messages_sent`/
end end
it "hides confidential fields inside deeply nested queries" do it "hides confidential fields inside deeply nested queries" do
response = execute("{ proposals(first: 1) { edges { node { public_author { encrypted_password } } } } }") expect do
expect(hidden_field?(response, "encrypted_password")).to be_truthy run_graphql_field("Proposal.public_author.encrypted_password", proposal)
end.to raise_error GraphQL::Testing::Helpers::FieldNotDefinedError, /no field named `encrypted_password`/
end end
describe "#comments" do describe "#comments" do

View File

@@ -7,28 +7,25 @@ describe Types::UserType do
it "does not link debates" do it "does not link debates" do
create(:debate, author: user) create(:debate, author: user)
response = execute("{ user(id: #{user.id}) { public_debates { edges { node { title } } } } }") response = run_graphql_field("User.public_debates", user)
received_debates = dig(response, "data.user.public_debates.edges")
expect(received_debates).to eq [] expect(response.items).to eq []
end end
it "does not link proposals" do it "does not link proposals" do
create(:proposal, author: user) create(:proposal, author: user)
response = execute("{ user(id: #{user.id}) { public_proposals { edges { node { title } } } } }") response = run_graphql_field("User.public_proposals", user)
received_proposals = dig(response, "data.user.public_proposals.edges")
expect(received_proposals).to eq [] expect(response.items).to eq []
end end
it "does not link comments" do it "does not link comments" do
create(:comment, author: user) create(:comment, author: user)
response = execute("{ user(id: #{user.id}) { public_comments { edges { node { body } } } } }") response = run_graphql_field("User.public_comments", user)
received_comments = dig(response, "data.user.public_comments.edges")
expect(received_comments).to eq [] expect(response.items).to eq []
end end
end end

View File

@@ -21,6 +21,7 @@ RSpec.configure do |config|
config.include(EmailSpec::Matchers) config.include(EmailSpec::Matchers)
config.include(CommonActions) config.include(CommonActions)
config.include(ActiveSupport::Testing::TimeHelpers) config.include(ActiveSupport::Testing::TimeHelpers)
config.include GraphQL::Testing::Helpers.for(ConsulSchema)
config.define_derived_metadata(file_path: Regexp.new("/spec/components/")) do |metadata| config.define_derived_metadata(file_path: Regexp.new("/spec/components/")) do |metadata|
metadata[:type] = :component metadata[:type] = :component

View File

@@ -7,14 +7,6 @@ module GraphQLAPI
response.dig(*path.split(".")) response.dig(*path.split("."))
end end
def hidden_field?(response, field_name)
data_is_empty = response["data"].nil?
error_message = /Field '#{field_name}' doesn't exist on type '[[:alnum:]]*'/
error_is_present = ((response["errors"].first["message"] =~ error_message) == 0)
data_is_empty && error_is_present
end
def extract_fields(response, collection_name, field_chain) def extract_fields(response, collection_name, field_chain)
fields = field_chain.split(".") fields = field_chain.split(".")
dig(response, "data.#{collection_name}.edges").map do |node| dig(response, "data.#{collection_name}.edges").map do |node|