Skip to content

Commit

Permalink
Merge pull request #638 from jfmengels/docs-for-maporfail
Browse files Browse the repository at this point in the history
Fix example for SelectionSet.mapOrFail
  • Loading branch information
dillonkearns authored Dec 30, 2024
2 parents b8d66d2 + 9b571ca commit e8e4ce5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Graphql/SelectionSet.elm
Original file line number Diff line number Diff line change
Expand Up @@ -715,35 +715,40 @@ combineDict ( key, selection ) acc =
{-| If the map function provided returns an `Ok` `Result`, it will map to that value.
If it returns an `Err`, the _entire_ response will fail to decode.
import Time exposing (Posix)
-- NOTE: Iso8601 comes from an external dependency in Elm >= 0.19:
-- https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/
import Github.Object
import Github.Object.Repository
import Github.Scalar
-- NOTE: Iso8601 comes from an external dependency in Elm >= 0.19:
-- https://package.elm-lang.org/packages/rtfeldman/elm-iso8601-date-strings/latest/
import Iso8601
import Graphql.SelectionSet as SelectionSet exposing (with)
import Iso8601
import Time exposing (Posix)
type alias Timestamps =
{ created : Posix
, updated : Posix
}
{ created : Posix
, updated : Posix
}
timestampsSelection : SelectionSet Timestamps Github.Object.Repository
timestampsSelection =
SelectionSet.succeed Timestamps
|> with (Repository.createdAt |> mapToDateTime)
|> with (Repository.updatedAt |> mapToDateTime)
mapToDateTime : Field Github.Scalar.DateTime scope -> Field Posix scope
mapToDateTime =
Field.mapOrFail
(\(Github.Scalar.DateTime value) ->
Iso8601.toTime value
|> Result.mapError (\_ -> "Failed to parse "
++ value ++ " as Iso8601 DateTime.")
|> Result.mapError
(\_ ->
"Failed to parse "
++ value
++ " as Iso8601 DateTime."
)
)
-}
mapOrFail : (decodesTo -> Result String mapsTo) -> SelectionSet decodesTo scope -> SelectionSet mapsTo scope
Expand Down

0 comments on commit e8e4ce5

Please sign in to comment.