Relay
It is recommended to follow the Relay Server Specs in the schema. All default Swift endpoint will comply with this spec out of the box. There's some useful abstracts and interfaces to help you on the way.
Currently, Relay only support Collections of data queried from the database.
#
UsageTo create a connection there's three basic steps.
#
1. Create a single typeThis is the list of types that will be returned by the query. For example a list (connection) of Movie's.
This type should implement the Node
interface.
When the Node Interface is queried by id, the fieldResolver will be called with the ID param. The fieldResolver should return the entity with the given ID. If the ID not passed as an arg, you should just return the $objectValue.
#
2. Create a connection typeThis is the type that will be returned by the query, the connection. This is fairly easy as the Relay Middleware will do most of the work for you. All you need to do create a connection and refer it to the type you created in step 1.
#
3. Add the connection to the queryThis is the last step. You need to add the connection to the query. So it actually becomes available.
Note that Relay expects a
Swift\Orm\Dbal\ResultCollectionInterface
as the result of the query. This is always the return value of any findMany query on the ORMs EntityManager. However, you can also use any other implementation of the interface.
#
Full exampleThe full example below as generators looks like this:
#
AdvancedFor a more advanced example: see the ORM Generator.