Skip to content

Commit

Permalink
Update for Elm 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
xtian committed May 11, 2018
1 parent 634c51a commit ba1f68e
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 85 deletions.
10 changes: 6 additions & 4 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm-community/json-extra": "2.6.0 <= v < 3.0.0",
"elm-community/list-extra": "7.0.1 <= v < 8.0.0",
"elm-community/string-extra": "1.4.0 <= v < 2.0.0",
"elm-lang/core": "6.0.0 <= v < 7.0.0",
"elm-lang/http": "2.0.0 <= v < 3.0.0",
"elm-lang/json": "1.0.0 <= v < 2.0.0",
"elm-lang/time": "1.0.0 <= v < 2.0.0",
"elm-lang/url": "1.0.0 <= v < 2.0.0",
"elm-lang/websocket": "1.0.3 <= v < 2.0.0",
"elm-community/json-extra": "2.6.0 <= v < 3.0.0",
"elm-community/list-extra": "7.0.1 <= v < 8.0.0",
"elm-community/string-extra": "1.4.0 <= v < 2.0.0",
"lukewestby/elm-string-interpolate": "1.0.2 <= v < 2.0.0"
},
"test-dependencies": {}
}
}
5 changes: 0 additions & 5 deletions ete_tests/src/RailsDemo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ postView post =
]


(=>) : a -> b -> ( a, b )
(=>) =
(,)


socketUrl : String
socketUrl =
"ws://localhost:8080/subscriptions"
Expand Down
21 changes: 8 additions & 13 deletions examples/src/Subscription.elm
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,15 @@ messageButtons =
)


(=>) : a -> b -> ( a, b )
(=>) =
(,)


characters : List ( String, String )
characters =
[ "1000" => "Luke"
, "1001" => "Vader"
, "1002" => "Han"
, "1003" => "Leia"
, "1004" => "Tarkin"
, "2000" => "Threepio"
, "2001" => "Artoo"
[ ( "1000", "Luke" )
, ( "1001", "Vader" )
, ( "1002", "Han" )
, ( "1003", "Leia" )
, ( "1004", "Tarkin" )
, ( "2000", "Threepio" )
, ( "2001", "Artoo" )
]


Expand All @@ -166,7 +161,7 @@ chatMessagesView model =
avatar =
character |> Maybe.map .avatarUrl |> Maybe.withDefault ""
in
li [] [ img [ style [ "width" => "40px", "padding-right" => "5px" ], src avatar ] [], (characterName ++ ": " ++ (phrase |> phraseToString)) |> text ]
li [] [ img [ style [ ( "width", "40px" ), ( "padding-right", "5px" ) ], src avatar ] [], (characterName ++ ": " ++ (phrase |> phraseToString)) |> text ]
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/Graphqelm/Document.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ are helpful for debugging and demo purposes.
import Graphqelm.Document.Field as Field
import Graphqelm.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphqelm.RawField exposing (RawField)
import Graphqelm.SelectionSet exposing (SelectionSet(SelectionSet))
import Graphqelm.SelectionSet exposing (SelectionSet(..))
import Json.Decode as Decode exposing (Decoder)
import String.Interpolate exposing (interpolate)

Expand Down
2 changes: 1 addition & 1 deletion src/Graphqelm/Document/Argument.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Graphqelm.Document.Argument exposing (serialize)

import Graphqelm.Internal.Builder.Argument as Argument exposing (Argument(Argument))
import Graphqelm.Internal.Builder.Argument as Argument exposing (Argument(..))
import Graphqelm.Internal.Encode as Encode


Expand Down
10 changes: 5 additions & 5 deletions src/Graphqelm/Document/Field.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Graphqelm.Document.Field exposing (serializeChildren)

import Graphqelm.Document.Argument as Argument
import Graphqelm.Document.Indent as Indent
import Graphqelm.RawField exposing (RawField(Composite, Leaf))
import Graphqelm.RawField exposing (RawField(..))
import List.Extra


Expand All @@ -29,12 +29,12 @@ alias fieldIndex fields field =


serialize : Maybe String -> Maybe Int -> RawField -> Maybe String
serialize alias mIndentationLevel field =
serialize aliasName mIndentationLevel field =
let
prefix =
case alias of
Just aliasName ->
aliasName
case aliasName of
Just aliasName_ ->
aliasName_
++ (case mIndentationLevel of
Just _ ->
": "
Expand Down
2 changes: 1 addition & 1 deletion src/Graphqelm/Field.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Graphqelm.Field exposing (Field(Field), map, mapOrFail, nonNullElementsOrFail, nonNullOrFail)
module Graphqelm.Field exposing (Field(..), map, mapOrFail, nonNullElementsOrFail, nonNullOrFail)

{-| `Field`s are automatically generated by the `graphqelm` CLI command.
You can use `Graphqelm.Field.map` to transform a value.
Expand Down
5 changes: 2 additions & 3 deletions src/Graphqelm/Http.elm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import Http
import Json.Decode
import Json.Encode
import Task exposing (Task)
import Time exposing (Time)


{-| An internal request as it's built up. Once it's built up, send the
Expand All @@ -56,7 +55,7 @@ type Request decodesTo
, headers : List Http.Header
, baseUrl : String
, expect : Json.Decode.Decoder decodesTo
, timeout : Maybe Time
, timeout : Maybe Float
, withCredentials : Bool
, queryParams : List ( String, String )
}
Expand Down Expand Up @@ -319,7 +318,7 @@ errorDecoder decoder =

decodeErrorWithData : GraphqlError.PossiblyParsedData a -> Json.Decode.Decoder (DataResult a)
decodeErrorWithData data =
GraphqlError.decoder |> Json.Decode.map ((,) data) |> Json.Decode.map Err
GraphqlError.decoder |> Json.Decode.map (Tuple.pair data) |> Json.Decode.map Err


{-| Add a header.
Expand Down
4 changes: 2 additions & 2 deletions src/Graphqelm/Http/QueryParams.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Graphqelm.Http.QueryParams exposing (urlWithQueryParams)

import Http
import Url


urlWithQueryParams : List ( String, String ) -> String -> String
Expand All @@ -24,7 +24,7 @@ queryPair ( key, value ) =

queryEscape : String -> String
queryEscape =
Http.encodeUri >> replace "%20" "+"
Url.percentEncode >> replace "%20" "+"


replace : String -> String -> String -> String
Expand Down
2 changes: 1 addition & 1 deletion src/Graphqelm/Internal/Builder/Argument.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Graphqelm.Internal.Builder.Argument exposing (Argument(Argument), optional, required)
module Graphqelm.Internal.Builder.Argument exposing (Argument(..), optional, required)

{-| **WARNING** `Graphqelm.Interal` modules are used by the `graphqelm` command line
code generator tool. They should not be consumed through hand-written code.
Expand Down
4 changes: 2 additions & 2 deletions src/Graphqelm/Internal/Builder/Object.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Internal functions for use by auto-generated code from the `graphqelm` CLI.
-}

import Dict
import Graphqelm.Field as Field exposing (Field(Field))
import Graphqelm.Field as Field exposing (Field(..))
import Graphqelm.Internal.Builder.Argument exposing (Argument)
import Graphqelm.RawField exposing (RawField)
import Graphqelm.SelectionSet exposing (FragmentSelectionSet(FragmentSelectionSet), SelectionSet(..))
import Graphqelm.SelectionSet exposing (FragmentSelectionSet(..), SelectionSet(..))
import Json.Decode as Decode exposing (Decoder)


Expand Down
16 changes: 8 additions & 8 deletions src/Graphqelm/Internal/Encode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ null =
{-| Encode a bool
-}
bool : Bool -> Value
bool bool =
Json.Encode.bool bool
bool value =
Json.Encode.bool value
|> Json


{-| Encode a string
-}
string : String -> Value
string string =
Json.Encode.string string
string value =
Json.Encode.string value
|> Json


{-| Encode an enum. The first argument is the toString function for that enum.
-}
enum : (a -> String) -> a -> Value
enum enumToString enum =
EnumValue (enumToString enum)
enum enumToString value =
EnumValue (enumToString value)


{-| Encode a list of Values
-}
list : (a -> Value) -> List a -> Value
list toValue list =
list
list toValue value =
value
|> List.map toValue
|> List

Expand Down
2 changes: 1 addition & 1 deletion src/Graphqelm/RawField.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Graphqelm.RawField exposing (RawField(Composite, Leaf), name)
module Graphqelm.RawField exposing (RawField(..), name)

import Graphqelm.Internal.Builder.Argument as Argument exposing (Argument)

Expand Down
4 changes: 2 additions & 2 deletions src/Graphqelm/SelectionSet.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Graphqelm.SelectionSet exposing (FragmentSelectionSet(FragmentSelectionSet), SelectionSet(SelectionSet), empty, hardcoded, map, succeed, with)
module Graphqelm.SelectionSet exposing (FragmentSelectionSet(..), SelectionSet(..), empty, hardcoded, map, succeed, with)

{-| The auto-generated code from the `graphqelm` CLI will provide `selection`
functions for Objects, Interfaces, and Unions in your GraphQL schema.
Expand Down Expand Up @@ -58,7 +58,7 @@ These types are built for you by the code generated by the `graphqelm` command l
-}

import Graphqelm.Field as Field exposing (Field(Field))
import Graphqelm.Field as Field exposing (Field(..))
import Graphqelm.RawField as RawField exposing (RawField)
import Json.Decode as Decode exposing (Decoder)
import List.Extra
Expand Down
22 changes: 11 additions & 11 deletions src/Graphqelm/Subscription/Protocol.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ for Elixir/Phoenix:
frameworkKnowledge : Graphqelm.Subscription.Protocol subscriptionDecodesTo
frameworkKnowledge =
{ initMessage =
Encode.list
Encode.list identity
[ Encode.string "1"
, Encode.string "1"
, Encode.string "__absinthe__:control"
, Encode.string "phx_join"
, Encode.object []
]
, heartBeatMessage =
Encode.list
Encode.list identity
[ Encode.null
, Encode.string "1"
, Encode.string "phoenix"
Expand All @@ -38,7 +38,7 @@ for Elixir/Phoenix:
]
, documentRequest =
\operation ->
Encode.list
Encode.list identity
[ Encode.string "1"
, Encode.string "1"
, Encode.string "__absinthe__:control"
Expand Down Expand Up @@ -80,27 +80,27 @@ phoenixAbsinthe : Protocol subscriptionDecodesTo
phoenixAbsinthe =
{ initMessage =
\referenceId ->
Encode.list
Encode.list identity
[ Encode.null
, Encode.string (toString referenceId)
, Encode.string (String.fromInt referenceId)
, Encode.string "__absinthe__:control"
, Encode.string "phx_join"
, Encode.object []
]
, heartBeatMessage =
\referenceId ->
Encode.list
Encode.list identity
[ Encode.null
, Encode.string (toString referenceId)
, Encode.string (String.fromInt referenceId)
, Encode.string "phoenix"
, Encode.string "heartbeat"
, Encode.object []
]
, documentRequest =
\referenceId operation ->
Encode.list
Encode.list identity
[ Encode.string "1"
, Encode.string (toString referenceId)
, Encode.string (String.fromInt referenceId)
, Encode.string "__absinthe__:control"
, Encode.string "doc"
, Encode.object [ ( "query", operation |> Encode.string ) ]
Expand Down Expand Up @@ -140,9 +140,9 @@ rails =
]
, heartBeatMessage =
\referenceId ->
Encode.list
Encode.list identity
[ Encode.null
, Encode.string (toString referenceId)
, Encode.string (String.fromInt referenceId)
, Encode.string "phoenix"
, Encode.string "heartbeat"
, Encode.object []
Expand Down
11 changes: 3 additions & 8 deletions tests/EncodeTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import Graphqelm.Internal.Encode
import Test exposing (Test, describe, test)


(=>) : a -> b -> ( a, b )
(=>) =
(,)


all : Test
all =
describe "encode"
Expand Down Expand Up @@ -37,9 +32,9 @@ all =
, test "non-empty object" <|
\() ->
Graphqelm.Internal.Encode.object
[ "number" => Graphqelm.Internal.Encode.int 47
, "boolean" => Graphqelm.Internal.Encode.bool True
, "enum" => Graphqelm.Internal.Encode.enum toString EMPIRE
[ ( "number", Graphqelm.Internal.Encode.int 47 )
, ( "boolean", Graphqelm.Internal.Encode.bool True )
, ( "enum", Graphqelm.Internal.Encode.enum toString EMPIRE )
]
|> Graphqelm.Internal.Encode.serialize
|> Expect.equal """{number: 47, boolean: true, enum: EMPIRE}"""
Expand Down
Loading

0 comments on commit ba1f68e

Please sign in to comment.