Skip to content

Commit 0c733de

Browse files
Merge pull request #41 from jamesmacaulay/0.19
Update to 2.0.0 for Elm 0.19
2 parents cc43254 + 1f163e1 commit 0c733de

File tree

13 files changed

+114
-118
lines changed

13 files changed

+114
-118
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ cache:
1111
os:
1212
- linux
1313

14-
env: ELM_VERSION=0.18.0
14+
env: ELM_VERSION=0.19.0
1515

1616
before_install:
1717
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
1818

1919
install:
2020
- node --version
2121
- npm --version
22-
- npm install -g elm@$ELM_VERSION elm-test
23-
- git clone https://github.com/NoRedInk/elm-ops-tooling
24-
- elm-ops-tooling/with_retry.rb elm package install --yes
22+
- npm install -g elm@$ELM_VERSION [email protected]
2523
# Faster compile on Travis.
2624
- |
2725
if [ ! -d sysconfcpus/bin ];

elm-package.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

elm.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "package",
3+
"name": "jamesmacaulay/elm-graphql",
4+
"summary": "A GraphQL request builder and HTTP client",
5+
"license": "BSD-3-Clause",
6+
"version": "2.0.0",
7+
"exposed-modules": [
8+
"GraphQL.Client.Http",
9+
"GraphQL.Request.Builder",
10+
"GraphQL.Request.Builder.Arg",
11+
"GraphQL.Request.Builder.Variable"
12+
],
13+
"elm-version": "0.19.0 <= v < 0.20.0",
14+
"dependencies": {
15+
"elm/core": "1.0.0 <= v < 2.0.0",
16+
"elm/http": "1.0.0 <= v < 2.0.0",
17+
"elm/json": "1.0.0 <= v < 2.0.0",
18+
"elm/url": "1.0.0 <= v < 2.0.0"
19+
},
20+
"test-dependencies": {
21+
"elm-explorations/test": "1.0.0 <= v < 2.0.0"
22+
}
23+
}

src/GraphQL/Client/Http.elm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import GraphQL.Client.Http.Util as Util
2121
import GraphQL.Request.Builder as Builder
2222
import Http
2323
import Task exposing (Task)
24-
import Time exposing (Time)
2524

2625

2726
{-| An error returned by the GraphQL server that indicates there was something wrong with the request.
@@ -93,7 +92,7 @@ type alias RequestOptions =
9392
{ method : String
9493
, headers : List Http.Header
9594
, url : String
96-
, timeout : Maybe Time
95+
, timeout : Maybe Float
9796
, withCredentials : Bool
9897
}
9998

src/GraphQL/Client/Http/Util.elm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import GraphQL.Response as Response
44
import Http
55
import Json.Decode
66
import Json.Encode
7-
import Time exposing (Time)
7+
import Url
88

99

1010
postBodyJson : String -> Maybe Json.Encode.Value -> Json.Encode.Value
@@ -36,13 +36,13 @@ parameterizedUrl url documentString variableValues =
3636
"?"
3737

3838
queryParam =
39-
firstParamPrefix ++ "query=" ++ Http.encodeUri documentString
39+
firstParamPrefix ++ "query=" ++ Url.percentEncode documentString
4040

4141
variablesParam =
4242
variableValues
4343
|> Maybe.map
4444
(\obj ->
45-
"&variables=" ++ Http.encodeUri (Json.Encode.encode 0 obj)
45+
"&variables=" ++ Url.percentEncode (Json.Encode.encode 0 obj)
4646
)
4747
|> Maybe.withDefault ""
4848
in
@@ -53,7 +53,7 @@ type alias RequestOptions =
5353
{ method : String
5454
, headers : List Http.Header
5555
, url : String
56-
, timeout : Maybe Time
56+
, timeout : Maybe Float
5757
, withCredentials : Bool
5858
}
5959

@@ -81,7 +81,7 @@ type alias RequestConfig a =
8181
, url : String
8282
, body : Http.Body
8383
, expect : Http.Expect a
84-
, timeout : Maybe Time
84+
, timeout : Maybe Float
8585
, withCredentials : Bool
8686
}
8787

src/GraphQL/Request/Builder.elm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,23 @@ request :
344344
vars
345345
-> Document operationType result vars
346346
-> Request operationType result
347-
request vars ((Document { operation, ast, serialized }) as document) =
347+
request vars ((Document { operation, ast, serialized }) as doc) =
348348
Request
349349
{ documentAST = ast
350350
, documentString = serialized
351351
, variableValues =
352-
(documentVariables document
352+
(documentVariables doc
353353
|> Variable.extractValuesFrom vars
354354
)
355-
, responseDataDecoder = documentResponseDecoder document
355+
, responseDataDecoder = documentResponseDecoder doc
356356
}
357357

358358

359359
{-| Get the serialized document body of a `Request`.
360360
-}
361361
requestBody : Request operationType result -> String
362-
requestBody (Request { documentString }) =
363-
documentString
362+
requestBody (Request requestRecord) =
363+
requestRecord.documentString
364364

365365

366366
variableValuesToJson : List ( String, AST.ConstantValue ) -> Maybe Encode.Value
@@ -384,8 +384,8 @@ jsonVariableValues (Request { variableValues }) =
384384
{-| Get a JSON decoder that can be used to decode the data contained in a successful response to a `Request`. If you're working with a conventional GraphQL response over HTTP, the returned `Decoder` works on the data found under the `"data"` key of the response.
385385
-}
386386
responseDataDecoder : Request operationType result -> Decoder result
387-
responseDataDecoder (Request { responseDataDecoder }) =
388-
responseDataDecoder
387+
responseDataDecoder (Request requestRecord) =
388+
requestRecord.responseDataDecoder
389389

390390

391391
fragmentDefinitionsFromOperation : Operation operationType result vars -> List AST.FragmentDefinitionInfo
@@ -878,7 +878,7 @@ Meanwhile, the selection set of `userSpec` itself would look like this wherever
878878
fragmentSpread :
879879
Fragment result vars
880880
-> SelectionSpec FragmentSpread (Maybe result) vars
881-
fragmentSpread ((Fragment { name, spec }) as fragment) =
881+
fragmentSpread ((Fragment { name, spec }) as fragmentRecord) =
882882
let
883883
astFragmentSpreadInfo =
884884
{ name = name
@@ -891,8 +891,8 @@ fragmentSpread ((Fragment { name, spec }) as fragment) =
891891
SelectionSpec
892892
(AST.FragmentSpread astFragmentSpreadInfo)
893893
(Decode.maybe << decoder)
894-
(fragmentVariables fragment)
895-
(mergeFragments [ fragmentAST fragment ] nestedFragments)
894+
(fragmentVariables fragmentRecord)
895+
(mergeFragments [ fragmentAST fragmentRecord ] nestedFragments)
896896

897897

898898
{-| Constructs a `SelectionSpec` for an object with a single inline fragment. Takes an optional `TypeCondition`, a list of optional directives, and a `ValueSpec` representing the selection set of the inline fragment. The directives are tuples whose first element is the name of the directive, and whose second element is a list of key-value tuples representing the directive arguments. Argument values are constructed using functions from [`GraphQL.Request.Builder.Value`](GraphQL-Request-Builder-Value).
@@ -1019,7 +1019,7 @@ enum : List ( String, result ) -> ValueSpec NonNull EnumType result vars
10191019
enum =
10201020
enumWithFallback
10211021
(\label ->
1022-
Decode.fail ("Unexpected enum value " ++ toString label)
1022+
Decode.fail ("Unexpected enum value " ++ Encode.encode 0 (Encode.string label))
10231023
)
10241024

10251025

@@ -1124,7 +1124,7 @@ decoderFromEnumLabel :
11241124
decoderFromEnumLabel fallbackDecoder labelledValues =
11251125
let
11261126
valueFromLabel =
1127-
flip Dict.get (Dict.fromList labelledValues)
1127+
(\key -> Dict.get key (Dict.fromList labelledValues))
11281128

11291129
decoder enumString =
11301130
case valueFromLabel enumString of
@@ -1168,7 +1168,7 @@ nullable (ValueSpec sourceType decoder vars fragments) =
11681168
case sourceType of
11691169
SpecifiedType typeInfo ->
11701170
ValueSpec
1171-
(SpecifiedType { typeInfo | nullability = nullableFlag })
1171+
(SpecifiedType (SpecifiedTypeInfo nullableFlag typeInfo.coreType typeInfo.join typeInfo.selectionSet))
11721172
(Decode.nullable << decoder)
11731173
vars
11741174
fragments
@@ -1474,5 +1474,5 @@ mergeFragments fragmentsA fragmentsB =
14741474
fragmentsA
14751475
++ (fragmentsB
14761476
|> List.filter
1477-
(\fragment -> not (List.any ((==) fragment) fragmentsA))
1477+
(\fragmentItem -> not (List.any ((==) fragmentItem) fragmentsA))
14781478
)

src/GraphQL/Request/Builder/Variable.elm

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ type Field source
6666
{-| Construct a `Variable` that has no default value, and therefore must extract its value from a `source`. The first argument is the name of the variable that appears in the GraphQL request document, and must be unique for that document. It should _not_ include any leading dollar sign (`$`). The second argument is a function that extracts a value of the required type from a `source`. The third argument is a `VariableSpec` that describes the type of the variable.
6767
-}
6868
required : String -> (source -> a) -> VariableSpec nullability a -> Variable source
69-
required name extract (VariableSpec _ typeRef convert) =
70-
RequiredVariable name typeRef (extract >> convert)
69+
required variableName extract (VariableSpec _ typeRef convert) =
70+
RequiredVariable variableName typeRef (extract >> convert)
7171

7272

7373
{-| Construct a `Variable` that has a default value, and therefore its `source` may or may not provide a value for it. The first three arguments are the same as for the `required` function, except that the function to extract a value from `source` must return a `Maybe` of the type expected by the `VariableSpec`. The last argument is a default value for the variable.
7474
7575
Note that the `VariableSpec` may be either `Nullable` or `NonNull`, but in both cases the variable definition is serialized _without_ a Non-Null modifier in the GraphQL request document, because optional variables may not be Non-Null in GraphQL. If you pass a `NonNull` `VariableSpec` into this function, it just means that you won't be able to represent an explicit `null` for the variable's value. If instead you pass a `Nullable` `VariableSpec` into this function, you will be able to represent an explicit `null` value for the variable, but you'll also have to deal with double-wrapped `Maybe` values – a missing value is then represented as a `Nothing` returned from your extraction function, and a `null` value is represented as `Just Nothing`. For this reason, it is recommended that you stick to `NonNull` `VariableSpec` values here unless you really need to be able to pass `null` explictly to the GraphQL server.
7676
-}
7777
optional : String -> (source -> Maybe a) -> VariableSpec nullability a -> a -> Variable source
78-
optional name extractMaybe (VariableSpec nullability typeRef convert) defaultValue =
79-
OptionalVariable name (TypeRef.nullable typeRef) (extractMaybe >> Maybe.map convert) (convert defaultValue)
78+
optional variableName extractMaybe (VariableSpec nullability typeRef convert) defaultValue =
79+
OptionalVariable variableName (TypeRef.nullable typeRef) (extractMaybe >> Maybe.map convert) (convert defaultValue)
8080

8181

8282
{-| A `VariableSpec` for the GraphQL `Int` type that extracts its value from an Elm `Int`.
@@ -190,8 +190,8 @@ field :
190190
-> (objVariableSource -> fieldVariableSource)
191191
-> VariableSpec nullability fieldVariableSource
192192
-> Field objVariableSource
193-
field name extract (VariableSpec _ typeRef convert) =
194-
Field name typeRef (extract >> convert >> Just)
193+
field fieldName extract (VariableSpec _ typeRef convert) =
194+
Field fieldName typeRef (extract >> convert >> Just)
195195

196196

197197
{-| Like `field`, except the extractor function must return a `Maybe` value. When the extracted value is `Nothing`, the field is not included in the object sent to the server at all. This works in a very similar way to the `optional` function, except that `optional` is used for entire optional variables while `optionalField` is used for optional fields of variable input objects.
@@ -222,14 +222,14 @@ optionalField :
222222
-> (objVariableSource -> Maybe fieldVariableSource)
223223
-> VariableSpec nullability fieldVariableSource
224224
-> Field objVariableSource
225-
optionalField name extract (VariableSpec _ typeRef convert) =
226-
Field name typeRef (extract >> Maybe.map convert)
225+
optionalField fieldName extract (VariableSpec _ typeRef convert) =
226+
Field fieldName typeRef (extract >> Maybe.map convert)
227227

228228

229229
fieldTuple : source -> Field source -> Maybe ( String, AST.ConstantValue )
230-
fieldTuple source (Field name _ convert) =
230+
fieldTuple source (Field fieldName _ convert) =
231231
convert source
232-
|> Maybe.map (\value -> ( name, value ))
232+
|> Maybe.map (\value -> ( fieldName, value ))
233233

234234

235235
valueFromSource : source -> Variable source -> Maybe ( String, AST.ConstantValue )
@@ -252,28 +252,28 @@ valueFromSource source var =
252252
name : Variable source -> String
253253
name var =
254254
case var of
255-
RequiredVariable name _ _ ->
256-
name
255+
RequiredVariable variableName _ _ ->
256+
variableName
257257

258-
OptionalVariable name _ _ _ ->
259-
name
258+
OptionalVariable variableName _ _ _ ->
259+
variableName
260260

261261

262262
{-| Returns the AST (abstract syntax tree) representation of a `Variable`.
263263
-}
264264
toDefinitionAST : Variable source -> AST.VariableDefinition
265265
toDefinitionAST var =
266266
case var of
267-
RequiredVariable name typeRef _ ->
267+
RequiredVariable variableName typeRef _ ->
268268
AST.VariableDefinition
269-
{ name = name
269+
{ name = variableName
270270
, variableType = typeRef
271271
, defaultValue = Nothing
272272
}
273273

274-
OptionalVariable name typeRef _ defaultValue ->
274+
OptionalVariable variableName typeRef _ defaultValue ->
275275
AST.VariableDefinition
276-
{ name = name
276+
{ name = variableName
277277
, variableType = typeRef
278278
, defaultValue = Just defaultValue
279279
}

src/GraphQL/Request/Document/AST/Serialize.elm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module GraphQL.Request.Document.AST.Serialize
55

66
import GraphQL.Request.Document.AST as AST
77
import String
8+
import Json.Encode as Encode
89

910

1011
serializeDocument : AST.Document -> String
@@ -118,13 +119,13 @@ serializeValue value =
118119
"$" ++ name
119120

120121
AST.IntValue int ->
121-
toString int
122+
String.fromInt int
122123

123124
AST.FloatValue float ->
124-
toString float
125+
String.fromFloat float
125126

126127
AST.StringValue string ->
127-
toString string
128+
Encode.encode 0 (Encode.string string)
128129

129130
AST.BooleanValue True ->
130131
"true"

src/GraphQL/Request/Document/AST/Value/Json/Encode.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ encode value =
3030
Json.string string
3131

3232
AST.ListValue values ->
33-
Json.list (List.map encode values)
33+
Json.list encode values
3434

3535
AST.ObjectValue kvPairs ->
3636
Json.object (List.map (Tuple.mapSecond encode) kvPairs)

src/GraphQL/Schema/Decode.elm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module GraphQL.Schema.Decode
1212
)
1313

1414
import Json.Decode as Decode exposing (Decoder, field, string, bool, null, list)
15+
import Json.Encode as Encode
1516
import GraphQL.Schema as Schema exposing (Schema)
1617
import Dict exposing (Dict)
1718

@@ -158,13 +159,13 @@ namedTypeDecoder =
158159
inputObjectTypeDecoder
159160

160161
_ ->
161-
Decode.fail ("unexpected kind for named type " ++ toString kind)
162+
Decode.fail ("unexpected kind for named type " ++ Encode.encode 0 (Encode.string kind))
162163
)
163164

164165

165166
namedTypeTupleDecoder : Decoder ( String, Schema.NamedType )
166167
namedTypeTupleDecoder =
167-
construct (,)
168+
construct (\a b -> ( a, b ))
168169
|> with (field "name" string)
169170
|> with namedTypeDecoder
170171

@@ -197,7 +198,7 @@ decoderFromDirectiveLocation loc =
197198
Decode.succeed Schema.InlineFragmentLocation
198199

199200
_ ->
200-
Decode.fail ("unexpected DirectiveLocation " ++ toString loc)
201+
Decode.fail ("unexpected DirectiveLocation " ++ Encode.encode 0 (Encode.string loc))
201202

202203

203204
directiveLocationDecoder : Decoder Schema.DirectiveLocation

0 commit comments

Comments
 (0)