After setting up our project, we're ready to create our Todo list and query it.
Let's create a Todo in our testable example. We do it by adding the following code to
go test should pass successfully.
As you can see, our Todos are too boring as they contain only the
ID field. Let's improve this example by adding
multiple fields to the schema in
After adding these fields, we need to run the code-generation as before:
As you may notice, all fields have a default value on creation except the
text field, which must be provided by
the user. Let's change our
example_test.go to follow these changes:
Wonderful! We created a schema in the database with 5 columns (
and created 2 items in our todo list, by inserting 2 rows to the table.
Let’s say we want to design our todo list so that an item can depend on another item. Therefore, we'll add a
edge to each Todo item, to get the item it depends on, and a back-reference edge named
children in order to get all
items that depend on it.
Let's change our schema again in
After adding these edges, we need to run the code-generation as before:
We continue our edges example, by updating the 2 todo items we just created. We define that item-2 ("Add Tracing Example") depends on item-1 ("Add GraphQL Example").
After connecting item-2 to item-1, we're ready to start querying our todo list.