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

Graphqelm.OptionalArgument

type OptionalArgument a = Present a | Absent | Null

This type is used to create values to pass in optional arguments.

  import Api.Enum.Episode as Episode exposing (Episode)
  import Api.Query as Query
  import Graphqelm.Operation exposing (RootQuery)
  import Graphqelm.OptionalArgument exposing (OptionalArgument(Null, Present))
  import Graphqelm.SelectionSet exposing (SelectionSet, with)


  query : SelectionSet Response RootQuery
  query =
      Query.selection Response
          |> with (Query.human { id = "1004" } human)
          |> with (Query.human { id = "1001" } human)
          |> with
              (Query.hero
                  (\optionals ->
                      { optionals
                          | episode = Present Episode.EMPIRE
                      }
                  )
                  hero
              )

An optional argument can be either present, absent, or null, so using a Maybe does not fully capture the GraphQL concept of an optional argument. For example, you could have a mutation that deletes an entry if a null argument is provided, or does nothing if the argument is absent. See The official GraphQL spec section on null for details.

fromMaybe : Maybe a -> OptionalArgument a

Convert a Maybe to an OptionalArgument.

module Graphqelm.OptionalArgument exposing (OptionalArgument(..), fromMaybe)

{-|

@docs OptionalArgument
@docs fromMaybe

-}


{-| This type is used to create values to pass in optional arguments.

      import Api.Enum.Episode as Episode exposing (Episode)
      import Api.Query as Query
      import Graphqelm.Operation exposing (RootQuery)
      import Graphqelm.OptionalArgument exposing (OptionalArgument(Null, Present))
      import Graphqelm.SelectionSet exposing (SelectionSet, with)


      query : SelectionSet Response RootQuery
      query =
          Query.selection Response
              |> with (Query.human { id = "1004" } human)
              |> with (Query.human { id = "1001" } human)
              |> with
                  (Query.hero
                      (\optionals ->
                          { optionals
                              | episode = Present Episode.EMPIRE
                          }
                      )
                      hero
                  )

An optional argument can be either present, absent, or null, so using a Maybe does not
fully capture the GraphQL concept of an optional argument. For example, you could have
a mutation that deletes an entry if a null argument is provided, or does nothing if
the argument is absent. See
[The official GraphQL spec section on null](http://facebook.github.io/graphql/October2016/#sec-Null-Value)
for details.

-}
type OptionalArgument a
    = Present a
    | Absent
    | Null


{-| Convert a `Maybe` to an OptionalArgument.
-}
fromMaybe : Maybe a -> OptionalArgument a
fromMaybe maybeValue =
    case maybeValue of
        Just value ->
            Present value

        Nothing ->
            Absent