Register field as a list of strings
The below code registers a field called listOfStrings
that returns a list of strings as the result:
add_action( 'graphql_register_types', function() {
register_graphql_field( 'RootQuery', 'listOfStrings', [
'type' => [ 'list_of' => 'String' ],
'resolve' => function() {
return [
'String One',
'String Two'
];
}
] );
} );
This field can now be queried:
{
listOfStrings
}