Skip to content

Commit c1bb0ac

Browse files
Merge pull request #780 from jaredhendrickson13/next_patch
fix(GraphQL): only mark types as nonNull if they are unconditional #778
2 parents d943a4e + d5e28a3 commit c1bb0ac

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Schemas/GraphQLSchema.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ class GraphQLSchema extends Schema {
127127
$type = Type::listOf($type);
128128
}
129129

130-
# Make this field non-nullable if it is required
131-
if ($field->required and !$ignore_required) {
130+
# Make this field non-nullable if it is required and unconditional
131+
if ($field->required and !$field->conditions and !$ignore_required) {
132132
$type = Type::nonNull($type);
133133
}
134134

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsGraphQLTestCase.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,17 @@ class APIModelsGraphQLTestCase extends TestCase {
388388
},
389389
);
390390
}
391+
392+
/**
393+
* Ensure we can query for model fields that are conditionally required. Regression test for #778
394+
*/
395+
public function test_query_conditionally_required_field(): void {
396+
# Query for interfaces including conditionally required fields and ensure no errors are returned.
397+
$graphql = new GraphQL(
398+
query: 'query {queryInterfaces {id ipaddr subnet descr typev4 track6_interface}}',
399+
client: $this->auth,
400+
);
401+
$graphql->create();
402+
$this->assert_is_empty($graphql->result->value['errors'] ?? []);
403+
}
391404
}

0 commit comments

Comments
 (0)