More examples
age2pierre opened this issue · comments
Hello,
I've been exploring this lib (and reasonml at the same time) quite recently, and even though the swapi example was a really great starting point, i've been missing a few recipes.
So far i've needed to add a scalar in my schema, and define a enum, here's how i've done :
let datetime: 'ctx. Schema.typ('ctx, option(BsLuxon.DateTime.dt)) =
Scalar({
name: "DateTime",
description: None,
serialize: dt => {
let isoDt: string = BsLuxon.DateTime.toISO((), dt);
`String(isoDt);
},
});
let draftValue = Schema.enumValue(~value=Chapital.Draft, "DRAFT");
let publishedValue = Schema.enumValue(~value=Chapital.Published, "PUBLISHED");
let archivedValue = Schema.enumValue(~value=Chapital.Archived, "ARCHIVED");
let assetStatus: 'ctx. Schema.typ('ctx, option(Chapital.assetStatus)) =
Enum({
name: "AssetStatus",
description: None,
values: [draftValue, publishedValue, archivedValue],
});
I'm not sure this is the right way to go (specially about the enum, i saw there was an makeEnum function but couldn't find the proper way to use it).
Cheers
The final Enum type must be created once for schema type and for argument type(since they are different types) and the makeEnum
function is a helper to help create both at once. But of course you can create each one individually. So your assetStatus
cannot be used in an argument type. I can give an example soon