diff --git a/codegen/schema/src/GraphQL/Client/CodeGen/Template/Enum.purs b/codegen/schema/src/GraphQL/Client/CodeGen/Template/Enum.purs index f6d6b50..f39bb85 100644 --- a/codegen/schema/src/GraphQL/Client/CodeGen/Template/Enum.purs +++ b/codegen/schema/src/GraphQL/Client/CodeGen/Template/Enum.purs @@ -162,11 +162,11 @@ instance bounded""" <> """ where top = """ - <> enumValueName headValue + <> enumValueName lastValue <> """ bottom = """ - <> enumValueName lastValue + <> enumValueName headValue <> """ diff --git a/src/GraphQL/Client/ToGqlString.purs b/src/GraphQL/Client/ToGqlString.purs index 04bf43e..f9335d4 100644 --- a/src/GraphQL/Client/ToGqlString.purs +++ b/src/GraphQL/Client/ToGqlString.purs @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/test/GraphQL/Client/ToGqlString.Test.purs b/test/GraphQL/Client/ToGqlString.Test.purs index 44470f9..5524b78 100644 --- a/test/GraphQL/Client/ToGqlString.Test.purs +++ b/test/GraphQL/Client/ToGqlString.Test.purs @@ -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(..)) @@ -79,7 +79,6 @@ spec = b }""" - it "converts aliases" $ toGqlQueryStringFormatted { a_alias: (Proxy :: _ "a") : { nested_alias: (Proxy :: _ "nested") }, b: unit } `shouldEqual` @@ -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") } @@ -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") } @@ -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 @@ -137,7 +141,8 @@ spec = b }""" it "ignores Ignore args" - $ toGqlQueryStringFormatted + $ + toGqlQueryStringFormatted { a: { i: IgnoreArg , a: [ 1, 2, 3 ] @@ -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` @@ -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) { @@ -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 @@ -196,9 +255,8 @@ spec = let cached = applyDir (Proxy :: _ "cached") in - toGqlQueryStringFormatted - (cached {} { a: unit } ) - + toGqlQueryStringFormatted + (cached {} { a: unit }) `shouldEqual` """@cached { a