This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

GraphQL.Request.Relay

Relay records and functions

type alias RelayData a = { pageInfo : PageInfo , edges : List (Edge a) }
type alias PageInfo = { startCursor : String , endCursor : String , hasNextPage : Bool , hasPreviousPage : Bool }
type alias Edge a = { cursor : String , node : a }
relayObject : ValueSpec NonNull ObjectType result vars -> ValueSpec NonNull ObjectType (RelayData result) vars

Constructs RelayData object with pageInfo and edges from a given object.

connectionNodes : ValueSpec NonNull ObjectType result vars -> ValueSpec NonNull ObjectType (List result) vars

Dive into Relay edges-node structure and extract list of objects. Pagination not suppoerted yet

module GraphQL.Request.Relay exposing (..)

{-| Relay records and functions

@docs RelayData, PageInfo, Edge, relayObject, connectionNodes

-}

import GraphQL.Request.Builder exposing (..)


{-| -}
type alias RelayData a =
    { pageInfo : PageInfo
    , edges : List (Edge a)
    }


{-| -}
type alias PageInfo =
    { startCursor : String
    , endCursor : String
    , hasNextPage : Bool
    , hasPreviousPage : Bool
    }


{-| -}
type alias Edge a =
    { cursor : String
    , node : a
    }


{-| Constructs `RelayData` object with pageInfo and edges from a given object.
-}
relayObject : ValueSpec NonNull ObjectType result vars -> ValueSpec NonNull ObjectType (RelayData result) vars
relayObject obj =
    let
        edge =
            object Edge
                |> with (field "cursor" [] string)
                |> with (field "node" [] obj)

        pageInfo =
            object PageInfo
                |> with (field "startCursor" [] string)
                |> with (field "endCursor" [] string)
                |> with (field "hasNextPage" [] bool)
                |> with (field "hasPreviousPage" [] bool)
    in
        object RelayData
            |> with (field "pageInfo" [] pageInfo)
            |> with (field "edges" [] <| list edge)


{-| Dive into Relay edges-node structure and extract list of objects. Pagination not suppoerted yet
-}
connectionNodes :
    ValueSpec NonNull ObjectType result vars
    -> ValueSpec NonNull ObjectType (List result) vars
connectionNodes spec =
    extract <|
        field "edges" [] <|
            list <|
                extract <|
                    field "node" [] spec