GraphQL
GraphQL Introduction
GraphQL is a query API language that executes queries by using a type system based on defined input data. GraphQL provides more specific inquiries with faster results and populate multiple inputs into one query.
Note: GraphQL endpoint permissions mirror permissions for the REST API. A user is only granted access to view grades based on that user’s permissions. For instance, a student cannot view grades for another student, but an instructor can view grades for any student in a course.
Using GraphQL
Canvas has included the tool GraphiQL, an in-browser graphical interface for interacting with GraphQL endpoints.
The GraphiQL interface can be viewed by adding /graphiql to the end of your Canvas production URL (e.g. your-institution.instructure.com/graphiql).
The /graphiql access can also be added to a test or beta environment URL. Requests from the selected environment will always return that environment’s data.
The Explorer sidebar displays all available queries and mutations. Any selected items display in the GraphiQL window. Once a query or mutation is selected, any values displayed in purple text identify the value as an input argument.
REST vs GraphQL
The Canvas REST API will continue to be available.
Fields are being added to the GraphQL API on an as-needed basis. The GraphQL API does not include everything that is currently in the REST API. Feel free to submit pull requests on github to add additional features or talk about it in the #canvas-lms
channel on libera.chat.
GraphQL Endpoint
POST /api/graphql
All GraphQL queries are posted to this endpoint.
Request Parameters
Parameter | Type | Description |
---|---|---|
query | string | the GraphQL query to execute |
variables | Hash | variable values as required by the supplied query |
Example Request:
Example Response
GraphQL in Canvas
id
vs _id
and the node
field
id
vs _id
and the node
fieldThe Canvas LMS GraphQL API follows the Relay Object Identification spec. Querying for an object's id
will return a global identifier instead of the numeric ids that are used in the REST API. The traditional ids can be queried by requesting the _id
field.
Most objects can be fetched by passing their GraphQL id
to the node
field:
A legacyNode
field is also available to fetch objects via the REST-style ids:
For commonly accessed object types, type-specific fields are provided:
Pagination
Canvas follows the Relay Connection Spec for paginating collections. Request reasonable page sizes to avoid being limited.
© Instructure, Inc. Generated on Wed Nov 6 14:19:59 2024 This documentation is generated directly from the Canvas LMS source code, available on Github.
Last updated