spec/graphql/schema/warden_spec.rb in graphql-1.3.0 vs spec/graphql/schema/warden_spec.rb in graphql-1.4.0

- old
+ new

@@ -107,12 +107,16 @@ UVULAR_TRILL end end def self.query_with_mask(str, mask, variables: {}) - Schema.execute(str, except: mask, root_value: Data, variables: variables) + run_query(str, except: mask, root_value: Data, variables: variables) end + + def self.run_query(str, options = {}) + Schema.execute(str, options.merge(root_value: Data)) + end end describe GraphQL::Schema::Warden do def type_names(introspection_result) @@ -147,11 +151,11 @@ query_result["errors"].map { |err| err["message"] } end describe "hiding fields" do let(:mask) { - -> (member) { member.metadata[:hidden_field] || member.metadata[:hidden_type] } + -> (member, ctx) { member.metadata[:hidden_field] || member.metadata[:hidden_type] } } it "causes validation errors" do query_string = %|{ phoneme(symbol: "ϕ") { name } }| res = MaskHelpers.query_with_mask(query_string, mask) @@ -192,12 +196,12 @@ assert_equal [], phoneme_fields end end describe "hiding types" do - let(:mask) { - -> (member) { member.metadata[:hidden_type] } + let(:whitelist) { + -> (member, ctx) { !member.metadata[:hidden_type] } } it "hides types from introspection" do query_string = %| { @@ -225,11 +229,11 @@ } } } | - res = MaskHelpers.query_with_mask(query_string, mask) + res = MaskHelpers.run_query(query_string, only: whitelist) # It's not visible by name assert_equal nil, res["data"]["Phoneme"] # It's not visible in `__schema` @@ -256,11 +260,11 @@ fragment f1 on Phoneme { name } | - res = MaskHelpers.query_with_mask(query_string, mask) + res = MaskHelpers.run_query(query_string, only: whitelist) expected_errors = [ "No such type Phoneme, so it can't be a fragment condition", "No such type Phoneme, so it can't be a fragment condition", ] @@ -273,17 +277,17 @@ unit(name: "Uvular Trill") { __typename } } | assert_raises(GraphQL::UnresolvedTypeError) { - MaskHelpers.query_with_mask(query_string, mask) + MaskHelpers.run_query(query_string, only: whitelist) } end describe "hiding an abstract type" do let(:mask) { - -> (member) { member.metadata[:hidden_abstract_type] } + -> (member, ctx) { member.metadata[:hidden_abstract_type] } } it "isn't present in a type's interfaces" do query_string = %| { @@ -301,11 +305,11 @@ end describe "hiding arguments" do let(:mask) { - -> (member) { member.metadata[:hidden_argument] || member.metadata[:hidden_input_type] } + -> (member, ctx) { member.metadata[:hidden_argument] || member.metadata[:hidden_input_type] } } it "isn't present in introspection" do query_string = %| { @@ -337,11 +341,11 @@ end end describe "hidding input type arguments" do let(:mask) { - -> (member) { member.metadata[:hidden_input_field] } + -> (member, ctx) { member.metadata[:hidden_input_field] } } it "isn't present in introspection" do query_string = %| { @@ -386,11 +390,11 @@ end end describe "hidding input types" do let(:mask) { - -> (member) { member.metadata[:hidden_input_object_type] } + -> (member, ctx) { member.metadata[:hidden_input_object_type] } } it "isn't present in introspection" do query_string = %| { @@ -431,10 +435,10 @@ end end describe "hiding enum values" do let(:mask) { - -> (member) { member.metadata[:hidden_enum_value] } + -> (member, ctx) { member.metadata[:hidden_enum_value] } } it "isn't present in introspection" do query_string = %| {