#Entities
You're viewing documentation for a previous version of this software. Switch to the latest stable version
Continuing from the setup, now we will be declaring entities for the GraphQL API.
Let's say for this example, we will have a user management system where the API can be used to create, find, update, and delete user profile(s).
#User profiles
Declaring the User
model is fairly straight forward.
Here, we have a couple properties and some computed ones as well. All things should be pretty self-explanatory.
ID type
Graphiti cannot diffentiate String
type from ID
type by default. Pioneer brought in a custom ID
struct to tackle this issue.
This customID
can be constructed from any string with its regular initializer or from string literal(s). It can also come from UUID
and String
using the extension .toID()
method.
It is also hashable so it can also be used as id
requirement for Identifiable
#User inputs
We also want an entity for the input that the API client will give to create and/or update a User profile.
#Datastore
In a real application, you want these User
(s) to be stored in a persistent database like PostgreSQL or something similar. For this example, we will be simplying the workflow by just building one in memory.
We will be taking advantange of Swift 5.5 actor
which a structure suitable for cocurrent state management.
This actor should look fairly straightforward.