diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Schemas/GraphQLSchema.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Schemas/GraphQLSchema.inc index 10b9d9e6..25562bd5 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Schemas/GraphQLSchema.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Schemas/GraphQLSchema.inc @@ -127,8 +127,8 @@ class GraphQLSchema extends Schema { $type = Type::listOf($type); } - # Make this field non-nullable if it is required - if ($field->required and !$ignore_required) { + # Make this field non-nullable if it is required and unconditional + if ($field->required and !$field->conditions and !$ignore_required) { $type = Type::nonNull($type); } diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsGraphQLTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsGraphQLTestCase.inc index 7521b035..cb1147e8 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsGraphQLTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsGraphQLTestCase.inc @@ -388,4 +388,17 @@ class APIModelsGraphQLTestCase extends TestCase { }, ); } + + /** + * Ensure we can query for model fields that are conditionally required. Regression test for #778 + */ + public function test_query_conditionally_required_field(): void { + # Query for interfaces including conditionally required fields and ensure no errors are returned. + $graphql = new GraphQL( + query: 'query {queryInterfaces {id ipaddr subnet descr typev4 track6_interface}}', + client: $this->auth, + ); + $graphql->create(); + $this->assert_is_empty($graphql->result->value['errors'] ?? []); + } }