...
Please read our beginners guide for a quick overview of GraphQL's core concepts: /wiki/spaces/~712020ed0261f15a044ee387ddaa27aaf37f0d/pages/840728681.
Schema
...
Types
In Totara we separate our , schemas are categorised based on their use -case. The cases. Each schema type - queries, mutations, types, and so on we define in one schema type has rules about whether it’s available in another. At Totara we have three schema types (use cases) - these are etc. - follows specific rules about its availability and interaction with other schema types. Totara defines three primary schema types: external, internal, and mobile.
External Schema
The external schema type is where the schema for our external APIs is written. This is a special schema type as the external schema is accessible by other schemas. In this way, it can thought of as the “root” schema.The external schema is any schema file placed under used for defining APIs accessible to external systems. It serves as the “root” schema since it can be accessed by other schemas.
External schemas are stored in the plugin's webapi/
directory. For example, in the local_todo
plugin, the external schema file would have a file path of be located at:
Code Block |
---|
server/local/todo/webapi/schema.graphqls |
...
Internal Schema
The internal schema type is where the schema for our internal client is written. The internal schema is also called , also referred to as ajax
in the codebase. The internal schema is not shared to another schema and is only available when using the internal schema. The internal schema is any schema file placed under the plugin’s , is designed for internal client operations. It is isolated and not accessible to other schema types.
Internal schemas are stored in the plugin's webapi/ajax/
directory. For example, in the local_todo
plugin, the internal schema file would have a file path of be located at:
Code Block |
---|
server/local/todo/webapi/ajax/schema.graphqls |
...
For more information, refer to Totara's Developer Documentation or check out our the quick-start guide below on creating an internal query in within this document.
Mobile Schema
The mobile schema type is where the schema for our mobile API is written. The mobile schema is used by our mobile app. This guide doesn’t cover the mobile API at this time.The mobile schema is any schema file placed under the plugin’s tailored for APIs used by the Totara mobile app.
Mobile schemas are stored in the plugin's webapi/mobile/
directory. For example, in the local_todo
plugin, the mobile schema file would have a file path of be located at:
Code Block |
---|
server/local/todo/webapi/mobile/schema.graphqls |
...
Quickstart - Create an Internal Query
...
Create the schema
Create a
webapi
directory in your plugin directory. For example, for mylocal_todo
plugin, this would be in/server/local/todo/
.Under the
webapi
create aajax
directoryCreate a
schema.graphqls
file under theajax
directoryIn
schema.graphqls
let’s define thetodo_item
type by adding the following:Code Block language graphql type local_todo_item { id: core_id title: String completed_at: core_date }
This adds a new type with
id
,title
andcompleted_at
which we will have access to when using this type.
...