spec/graphql/schema/warden_spec.rb in graphql-1.6.8 vs spec/graphql/schema/warden_spec.rb in graphql-1.7.0
- old
+ new
@@ -67,22 +67,45 @@
argument :miles, !types.Float do
metadata :hidden_input_field, true
end
end
+ CheremeInput = GraphQL::InputObjectType.define do
+ name "CheremeInput"
+ input_field :name, types.String
+ end
+
+ Chereme = GraphQL::ObjectType.define do
+ name "Chereme"
+ description "A basic unit of signed communication"
+ field :name, types.String.to_non_null_type
+ end
+
+ Character = GraphQL::ObjectType.define do
+ name "Character"
+ interfaces [LanguageMemberInterface]
+ field :code, types.Int
+ end
+
QueryType = GraphQL::ObjectType.define do
name "Query"
field :languages, LanguageType.to_list_type do
- argument :within, WithinInputType, "Find languages nearby a point"
+ argument :within, WithinInputType, "Find languages nearby a point" do
+ metadata :hidden_argument_with_input_object, true
+ end
end
field :language, LanguageType do
metadata :hidden_field, true
argument :name, !types.String do
metadata :hidden_argument, true
end
end
+ field :chereme, Chereme do
+ metadata :hidden_field, true
+ end
+
field :phonemes, PhonemeType.to_list_type do
argument :manners, MannerEnum.to_list_type, "Filter phonemes by manner of articulation"
end
field :phoneme, PhonemeType do
@@ -99,10 +122,16 @@
MutationType = GraphQL::ObjectType.define do
name "Mutation"
field :add_phoneme, PhonemeType do
argument :symbol, types.String
end
+
+ field :add_chereme, types.String do
+ argument :chereme, CheremeInput do
+ metadata :hidden_argument, true
+ end
+ end
end
module FilterInstrumentation
def self.before_query(query)
if query.context[:filters]
@@ -118,10 +147,11 @@
Schema = GraphQL::Schema.define do
query QueryType
mutation MutationType
subscription MutationType
+ orphan_types [Character]
resolve_type ->(type, obj, ctx) { PhonemeType }
instrument :query, FilterInstrumentation
end
module Data
@@ -223,10 +253,21 @@
describe "hiding fields" do
let(:mask) {
->(member, ctx) { member.metadata[:hidden_field] || member.metadata[:hidden_type] }
}
+ it "hides types if no other fields are using it" do
+ query_string = %|
+ {
+ Chereme: __type(name: "Chereme") { fields { name } }
+ }
+ |
+
+ res = MaskHelpers.query_with_mask(query_string, mask)
+ assert_nil res["data"]["Chereme"]
+ end
+
it "causes validation errors" do
query_string = %|{ phoneme(symbol: "ϕ") { name } }|
res = MaskHelpers.query_with_mask(query_string, mask)
err_msg = res["errors"][0]["message"]
assert_equal "Field 'phoneme' doesn't exist on type 'Query'", err_msg
@@ -368,17 +409,42 @@
res = MaskHelpers.query_with_mask(query_string, mask)
interfaces_names = res["data"]["__type"]["interfaces"].map { |i| i["name"] }
refute_includes interfaces_names, "LanguageMember"
end
+
+ it "hides implementations if they are not referenced anywhere else" do
+ query_string = %|
+ {
+ __type(name: "Character") {
+ fields { name }
+ }
+ }
+ |
+
+ res = MaskHelpers.query_with_mask(query_string, mask)
+ type = res["data"]["__type"]
+ assert_equal nil, type
+ end
end
end
describe "hiding arguments" do
let(:mask) {
->(member, ctx) { member.metadata[:hidden_argument] || member.metadata[:hidden_input_type] }
}
+
+ it "hides types if no other fields or arguments are using it" do
+ query_string = %|
+ {
+ CheremeInput: __type(name: "CheremeInput") { fields { name } }
+ }
+ |
+
+ res = MaskHelpers.query_with_mask(query_string, mask)
+ assert_nil res["data"]["CheremeInput"]
+ end
it "isn't present in introspection" do
query_string = %|
{
Query: __type(name: "Query") { fields { name, args { name } } }