Totara Learn Open Discussions

External API custom endpoints

 
Gabriel Baierle
External API custom endpoints
de Gabriel Baierle - Tuesday, 24 de October de 2023, 07:32
 

Hi. I'm a developer and want to add new endpoints to get data from custom Totara plugins. I'd like to incorporate this endpoints to the new graphql External API queries, but I didn't find any docs on how to add new endpoints there.

Any suggestion and/or good practice on how to do it?

Craig Eves
Re: External API custom endpoints
de Craig Eves (Totara Support) - Tuesday, 24 de October de 2023, 16:15
Grupo Totara

Hi Gabriel

Have you had a look at the Developers documentation on GraphQL this includes some examples that may be of help. If there are any gaps you want to ask questions on then you or your Partner can ask through creating a support ticket.

regards



Gabriel Baierle
Re: External API custom endpoints
de Gabriel Baierle - Saturday, 4 de November de 2023, 13:11
 

Following the docs I've created the following structure:

  • local/plugin/webapi/external/get_completions.graphql

query local_plugin_get_completions{

local_plugin_get_completions{ id }

}

  • local/plugin/webapi/external/schema.graphqls

extend type Query {

local_plugin_get_completions: [local_plugin_get_completions!]!

}

type local_plugin_get_completions{

id: core_id,

}

  • local/plugin/classes/webapi/resolver/query

class get_completions extends \core\webapi\query_resolver {

public static function resolve(array $args, execution_context $ec) {

return [ 'id' => 'test' ];

}

}

When sending the request, I get a 200 response with empty data, no error in the server side. What am I missing here or how shauld I add new queries to the Totara External GraphQL API?