This release of Space Cloud has some significant changes to the schema module which makes modelling and using the CRUD module of Space Cloud very easy.
Explicit foreign key
The @relation
directive has been dropped in favour of the @foreign
directive to make things more explicit and avoid the confusion with the @link
directive which is used for modelling relations.
Note: This is a breaking change. Follow the migration guide below to upgrade to
v0.14.0
So if your schema for foreign key looked like this:
type article {
id: ID! @primary
title: String!
author_id: author! @relation
}
Then you will have to change it to:
type article {
id: ID! @primary
title: String!
author_id: ID! @foreign(table: "author", field: "id")
}
Migration guide
- First, Stop Space Cloud.
- Then open the config file in a code-editor/nano/vim, etc.
- Locate all the tables in the config where you have used the
@relation
directive. - Replace
@relation
to@foreign
directive with thetable
andfield
arguments to dictate the target of the foreign key as shown in the above example. - Change the type of the field with
@relation
directive toID
as shown in the above example. - Save the config file and start Space Cloud with this updated config file.
Simplified joins
Now you can query relational data by making a simple query like this on frontend:
query {
author {
id
name
articles {
id
title
}
}
}
For this you would have to specify a @link
directive to describe the relationship between types like this:
type author {
id: ID! @primary
name: String!
articles: [article] @link(table: "article", from: "id", to: "author_id")
}
type article {
id: ID! @primary
title: String!
author_id: ID! @foreign(table: "author", field: "id")
}
Read more about links and modelling relationships.
This solves #494
Returns the inserted fields in insert mutations
You can now ask for the fields of the objects inserted in a mutation. Solves #511