This course is no longer maintained and may be out-of-date. While it remains available for reference, its content may not reflect the latest updates, best practices, or supported features.
Query Variables
What is a variable in GraphQL context?
GraphQL has a first-class way to factor dynamic values out of the query, and pass them as a separate dictionary. These values are called variables. In our case, we are defining the object to be inserted as a mutation.
So let's define the graphql mutation to be used.
Open src/app/Todo/TodoInput.ts
and add the following code:
import { Component, OnInit, Input } from '@angular/core';+ import { gql } from 'apollo-angular';+ const ADD_TODO = gql `+ mutation ($todo: String!, $isPublic: Boolean!) {+ insert_todos(objects: {title: $todo, is_public: $isPublic}) {+ affected_rows+ returning {+ id+ title+ created_at+ is_completed+ }+ }+ }+ `;@Component({selector: 'TodoInput',templateUrl: './TodoInput.template.html',})export class TodoInput {...}
What does this mutation do?
The mutation inserts into todos
table with the $objects variable being passed as one todo type.
Awesome! We have defined our first graphql mutation.
Build apps and APIs 10x faster
Built-in authorization and caching
8x more performant than hand-rolled APIs

