|
| 1 | +-- | Get the graphql fields from a data type |
| 2 | +module GraphQL.Client.GetFields (class GetFieldsStandard, PropGetFieldsStandard, getFieldsStandard) where |
| 3 | + |
| 4 | +import Prelude |
| 5 | + |
| 6 | +import Data.HeytingAlgebra (class HeytingAlgebraRecord, tt) |
| 7 | +import Data.Maybe (Maybe) |
| 8 | +import Heterogeneous.Mapping (class HMap, class Mapping, hmap) |
| 9 | +import Prim.RowList (class RowToList) |
| 10 | +import Type.Proxy (Proxy(..)) |
| 11 | + |
| 12 | +class GetFieldsStandard :: forall k. k -> Type -> Constraint |
| 13 | +class GetFieldsStandard t fields | t -> fields where |
| 14 | + getFieldsStandard :: Proxy t -> fields |
| 15 | + |
| 16 | +data PropGetFieldsStandard |
| 17 | + = PropGetFieldsStandard |
| 18 | + |
| 19 | +data PropToProxy |
| 20 | + = PropToProxy |
| 21 | + |
| 22 | +instance getFieldsStandardRecord :: |
| 23 | + ( RowToList r t |
| 24 | + , HeytingAlgebraRecord t r r |
| 25 | + , HMap PropGetFieldsStandard { | r } fields |
| 26 | + , HMap PropGetFieldsStandard { | input } { | r } |
| 27 | + ) => |
| 28 | + GetFieldsStandard { | input } fields where |
| 29 | + getFieldsStandard _ = recordGetFieldsStandard (tt :: { | r }) |
| 30 | +else instance getFieldsStandardMaybe :: GetFieldsStandard a fields => GetFieldsStandard (Maybe a) fields where |
| 31 | + getFieldsStandard _ = getFieldsStandard (Proxy :: _ a) |
| 32 | +else instance getFieldsStandardArray :: GetFieldsStandard a fields => GetFieldsStandard (Array a) fields where |
| 33 | + getFieldsStandard _ = getFieldsStandard (Proxy :: _ a) |
| 34 | +else instance getFieldsStandardLeaf :: GetFieldsStandard a Unit where |
| 35 | + getFieldsStandard _ = unit |
| 36 | + |
| 37 | + |
| 38 | +instance propToProxy :: |
| 39 | + Mapping PropToProxy t (Proxy t) where |
| 40 | + mapping PropToProxy _ = Proxy |
| 41 | + |
| 42 | +recordGetFieldsStandard :: |
| 43 | + forall t fields. |
| 44 | + HMap PropGetFieldsStandard ({ | t }) fields => { | t } -> fields |
| 45 | +recordGetFieldsStandard = hmap PropGetFieldsStandard |
| 46 | + |
| 47 | + |
| 48 | +instance propGetFieldsStandard :: |
| 49 | + (GetFieldsStandard t fields) => |
| 50 | + Mapping PropGetFieldsStandard t fields where |
| 51 | + mapping PropGetFieldsStandard _ = getFieldsStandard (Proxy :: _ t) |
| 52 | + |
0 commit comments