Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? []);
}
}