Totara Learn Open Discussions

External API custom endpoints

 
BaierleGabriel
External API custom endpoints
BaierleGabriel 发表于 2023年10月24日 Tuesday 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
Eves (Totara Support)Craig 发表于 2023年10月24日 Tuesday 16:15
小组 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



BaierleGabriel
Re: External API custom endpoints
BaierleGabriel 发表于 2023年11月4日 Saturday 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?