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

Directives not respecting warden: Add test failure #4882

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 35 additions & 8 deletions spec/graphql/schema/warden_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class PublicType < BaseObject
field :test, String
end

class CheremeDirective < GraphQL::Schema::Directive
graphql_name("cheremeDirectives")
locations(GraphQL::Schema::Directive::OBJECT)
end

class CheremeWithInterface < BaseObject
# Commenting this would make the test pass
implements PublicInterfaceType
Expand All @@ -176,6 +181,8 @@ class CheremeWithInterface < BaseObject
class Chereme < BaseObject
description "A basic unit of signed communication"
implements LanguageMemberType
directive CheremeDirective

field :name, String, null: false

field :chereme_with_interface, CheremeWithInterface
Expand Down Expand Up @@ -395,6 +402,26 @@ def error_messages(query_result)
assert_nil res["data"]["CheremeWithInterface"]
end

it "hides directives if no other fields are using it" do
query_string = %|
{
__schema { directives { name } }
}
|

res = MaskHelpers.query_with_mask(query_string, mask)
expected_directives = ["include", "skip", "deprecated", "oneOf", "specifiedBy"]

# Failure:
# GraphQL::Schema::Warden::hiding fields#test_0003_hides directives if no other fields are using it
# Minitest::Assertion: --- expected
# +++ actual
# @@ -1 +1 @@
# -["include", "skip", "deprecated", "oneOf", "specifiedBy"]
# +["include", "skip", "deprecated", "oneOf", "specifiedBy", "cheremeDirectives"]
assert_equal(expected_directives, res["data"]["__schema"]["directives"].map { |d| d["name"] })
end

it "causes validation errors" do
query_string = %|{ phoneme(symbol: "ϕ") { name } }|
res = MaskHelpers.query_with_mask(query_string, mask)
Expand Down Expand Up @@ -707,15 +734,15 @@ def self.visible?(member, context)
}

it "hides types if no other fields or arguments are using it" do
query_string = %|
{
CheremeInput: __type(name: "CheremeInput") { fields { name } }
}
|
query_string = %|
{
CheremeInput: __type(name: "CheremeInput") { fields { name } }
}
|

res = MaskHelpers.query_with_mask(query_string, mask)
assert_nil res["data"]["CheremeInput"]
end
res = MaskHelpers.query_with_mask(query_string, mask)
assert_nil res["data"]["CheremeInput"]
end

it "isn't present in introspection" do
query_string = %|
Expand Down