fix empty input object types in introspection result when allowedFields for a type is empty (#412)

When there are no allowed fields for a type (via `TypePermissions`),
engine creates related input object types (like `<TypeName>OrderBy`)
with no fields. This results in an invalid introspection result. Client
libraries fail with validation error.

This PR fixes the issue.

V3_GIT_ORIGIN_REV_ID: a45a56b1f503f6ab99f250884957b6fc723cf9c8
This commit is contained in:
Anon Ray 2024-03-28 13:16:16 +05:30 committed by hasura-bot
parent c60a2e7113
commit 1b4173011f
2 changed files with 36 additions and 2 deletions

View File

@ -4,7 +4,16 @@
"__type": {
"name": "ActorsByMovieArgs",
"kind": "INPUT_OBJECT",
"inputFields": []
"inputFields": [
{
"name": "_no_fields_accessible",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
]
}
}
},
@ -13,7 +22,16 @@
"__type": {
"name": "ActorsByMovieArgs",
"kind": "INPUT_OBJECT",
"inputFields": []
"inputFields": [
{
"name": "_no_fields_accessible",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
]
}
}
},

View File

@ -252,6 +252,8 @@ fn object_type<'s, S: schema::SchemaContext>(
})
})
.collect::<Vec<_>>();
// can't create dummy field inside the if-block, as it won't
// live long enough
let no_fields_accessible_name = mk_name!("_no_fields_accessible");
let dummy_field = schema::Field::new(
no_fields_accessible_name,
@ -417,6 +419,20 @@ fn input_object_type<'s, S: schema::SchemaContext>(
})
})
.collect::<Vec<_>>();
// can't create dummy field inside the if-block, as it won't
// live long enough
let no_fields_accessible_name = mk_name!("_no_fields_accessible");
let dummy_field = schema::InputField::new(
no_fields_accessible_name,
None,
S::introspection_node(),
ast::TypeContainer::named_null(RegisteredTypeName::string()),
None,
schema::DeprecationStatus::NotDeprecated,
);
if allowed_fields.is_empty() {
allowed_fields.push(&dummy_field)
}
allowed_fields.sort_by(|f1, f2| f1.name.cmp(&f2.name));
array_response(&allowed_fields, |input_field| {
input_value(schema, namespace, input_field, &field.selection_set)