Skip to content

Commit

Permalink
Merge pull request #136 from OxfordAbstracts/fix-enum-top
Browse files Browse the repository at this point in the history
Fix enum top
  • Loading branch information
roryc89 authored Apr 12, 2024
2 parents d801023 + d4c6ee1 commit 27f5614
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 30 deletions.
4 changes: 2 additions & 2 deletions codegen/schema/src/GraphQL/Client/CodeGen/Template/Enum.purs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ instance bounded"""
<>
""" where
top = """
<> enumValueName headValue
<> enumValueName lastValue
<>
"""
bottom = """
<> enumValueName lastValue
<> enumValueName headValue
<>
"""
Expand Down
9 changes: 1 addition & 8 deletions src/GraphQL/Client/ToGqlString.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ module GraphQL.Client.ToGqlString

import Prelude

import Data.Argonaut.Decode (class DecodeJson)
import Data.Argonaut.Encode (class EncodeJson)
import Data.Array (fold, foldMap, intercalate, length, mapWithIndex)
import Data.Array as Array
import Data.Date (Date)
Expand All @@ -49,7 +47,7 @@ import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..), isJust, maybe)
import Data.Monoid (guard, power)
import Data.Newtype (class Newtype, unwrap)
import Data.Newtype (unwrap)
import Data.String (codePointFromChar, fromCodePointArray, joinWith, toCodePointArray)
import Data.String.CodeUnits as String
import Data.String.Regex (split)
Expand All @@ -70,8 +68,6 @@ import GraphQL.Client.NullArray (NullArray)
import GraphQL.Client.Union (GqlUnion(..))
import GraphQL.Client.Variable (Var)
import GraphQL.Client.Variables (WithVars, getQuery)
import GraphQL.Hasura.Decode (class DecodeHasura)
import GraphQL.Hasura.Encode (class EncodeHasura)
import Heterogeneous.Folding (class FoldingWithIndex, class HFoldlWithIndex, hfoldlWithIndex)
import Type.Proxy (Proxy(..))
import Unsafe.Coerce (unsafeCoerce)
Expand Down Expand Up @@ -426,9 +422,6 @@ instance propToGqlArg ::
`List.Cons`
kvs

-- pre <> reflectSymbol prop <> ": " <> toGqlArgStringImpl a
-- where
-- pre = if str == "" then "" else str <> ", "
gqlArgStringRecord
:: forall r
. HFoldlWithIndex PropToGqlArg KeyVals { | r } KeyVals
Expand Down
98 changes: 78 additions & 20 deletions test/GraphQL/Client/ToGqlString.Test.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude

import GraphQL.Client.Alias ((:))
import GraphQL.Client.Alias.Dynamic (Spread(..))
import GraphQL.Client.Args (IgnoreArg(..), (++), (+++), (=>>))
import GraphQL.Client.Args (IgnoreArg(..), OrArg(..), (++), (+++), (=>>))
import GraphQL.Client.Directive (applyDir)
import GraphQL.Client.ToGqlString (gqlArgStringRecordTopLevel, toGqlQueryString, toGqlQueryStringFormatted)
import GraphQL.Client.Variable (Var(..))
Expand Down Expand Up @@ -79,7 +79,6 @@ spec =
b
}"""


it "converts aliases"
$ toGqlQueryStringFormatted { a_alias: (Proxy :: _ "a") : { nested_alias: (Proxy :: _ "nested") }, b: unit }
`shouldEqual`
Expand All @@ -90,10 +89,12 @@ spec =
b
}"""
it "converts aliases and nested args"
$ toGqlQueryStringFormatted
$
toGqlQueryStringFormatted
{ a_alias:
(Proxy :: _ "a")
: { arg: "abc"
:
{ arg: "abc"
, where: { id: { eq: 10 } }
}
=>> { nested_alias: (Proxy :: _ "nested") }
Expand All @@ -107,10 +108,12 @@ spec =
b
}"""
it "converts aliases and nested args (unformatted)"
$ toGqlQueryString
$
toGqlQueryString
{ a_alias:
(Proxy :: _ "a")
: { arg: "abc"
:
{ arg: "abc"
, where: { id: { eq: 10 } }
}
=>> { nested_alias: (Proxy :: _ "nested") }
Expand All @@ -119,12 +122,13 @@ spec =
`shouldEqual`
""" { a_alias: a(arg: "abc", where: {id: {eq: 10}}) { nested_alias: nested} b}"""
it "converts array args"
$ toGqlQueryStringFormatted
$
toGqlQueryStringFormatted
{ a:
{ a: [ 1, 2, 3 ]
, b: 1 ++ 2 ++ 3 ++ 4
, c: ["a", "b"] +++ [1, 2]
, d: ([] :: Array Int) +++ ["a", "b"] +++ [1, 2] +++ ([] :: Array Int) +++ [ "c", "d"] +++ ([] :: Array Int)
, c: [ "a", "b" ] +++ [ 1, 2 ]
, d: ([] :: Array Int) +++ [ "a", "b" ] +++ [ 1, 2 ] +++ ([] :: Array Int) +++ [ "c", "d" ] +++ ([] :: Array Int)
}
=>> { nested: unit }
, b: unit
Expand All @@ -137,7 +141,8 @@ spec =
b
}"""
it "ignores Ignore args"
$ toGqlQueryStringFormatted
$
toGqlQueryStringFormatted
{ a:
{ i: IgnoreArg
, a: [ 1, 2, 3 ]
Expand All @@ -154,9 +159,64 @@ spec =
nested
}
b
}"""
it "ignores OrArg Ignore args"
$
toGqlQueryStringFormatted
{ a:
{ i: (ArgL IgnoreArg :: OrArg IgnoreArg String)
, a: [ 1, 2, 3 ]
, b: (ArgR IgnoreArg :: OrArg Int IgnoreArg)
, c: "X"
, d: (ArgL IgnoreArg :: OrArg IgnoreArg Int)
}
=>> { nested: unit }
, b: unit
}
`shouldEqual`
""" {
a(a: [1, 2, 3], c: "X") {
nested
}
b
}"""
it "ignores nested Ignore args"
$
toGqlQueryStringFormatted
{ a:
{ parent:
{ i: IgnoreArg
, a: [ 1, 2, 3 ]
, b: IgnoreArg
, c: "X"
, d: IgnoreArg
}
}
=>> { nested: unit }
}
`shouldEqual`
" {\n a(parent: {a: [1, 2, 3], c: \"X\"}) {\n nested\n }\n}"
it "ignores Ignore args with AndArgs"
$
toGqlQueryStringFormatted
{ a:
{ arg:
[ { i: IgnoreArg
}
]
+++ [ { a: 1 } ]
}
=>> { nested: unit }
}
`shouldEqual`
""" {
a(arg: [{}, {a: 1}]) {
nested
}
}"""
it "handles variables"
$ toGqlQueryStringFormatted
$
toGqlQueryStringFormatted
{ a: { arg: Var :: _ "var1" _ } =>> { nested: unit }
}
`shouldEqual`
Expand All @@ -166,9 +226,9 @@ spec =
}
}"""
it "handles dynamic aliases"
$ toGqlQueryStringFormatted
(Spread (Proxy :: _ "b") [ { arg: 10}, { arg: 20}, { arg: 30}] { field: unit })

$
toGqlQueryStringFormatted
(Spread (Proxy :: _ "b") [ { arg: 10 }, { arg: 20 }, { arg: 30 } ] { field: unit })
`shouldEqual`
""" {
_0: b(arg: 10) {
Expand All @@ -185,9 +245,8 @@ spec =
let
cached = applyDir (Proxy :: _ "cached")
in
toGqlQueryStringFormatted
(cached {ttl: 10} { a: unit } )

toGqlQueryStringFormatted
(cached { ttl: 10 } { a: unit })
`shouldEqual`
"""@cached(ttl: 10) {
a
Expand All @@ -196,9 +255,8 @@ spec =
let
cached = applyDir (Proxy :: _ "cached")
in
toGqlQueryStringFormatted
(cached {} { a: unit } )

toGqlQueryStringFormatted
(cached {} { a: unit })
`shouldEqual`
"""@cached {
a
Expand Down

0 comments on commit 27f5614

Please sign in to comment.