Skip to content

Commit

Permalink
fix enum template
Browse files Browse the repository at this point in the history
  • Loading branch information
roryc89 committed Jan 26, 2021
1 parent 3fde6e3 commit 502c9af
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ jobs:
node-version: 12.x

- run: npm i
- run: npm run bundle
- run: node ./run-example-tests.js
21 changes: 8 additions & 13 deletions gen-schema-bundled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"exec-sh": "^0.3.4",
"graphqurl": "^0.3.3",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2"
"mkdirp": "1.0.4",
"rimraf": "3.0.2"
}
}
47 changes: 22 additions & 25 deletions src/GraphQL/Client/CodeGen/Template/Enum.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template ::
} ->
String
template modulePrefix { name, values } =
"""module """ <> vals.modulePrefix <> """Enum.""" <> vals.name <> """ where
"""module """ <> modulePrefix <> """Enum.""" <> name <> """ where
import Prelude
Expand All @@ -22,40 +22,37 @@ import Foreign (ForeignError(..), fail)
import GraphQL.Client.Args (class ArgGql)
import GraphQL.Client.ToGqlString (class GqlArgString)
data """ <> vals.name <> """
= """ <> vals.enumCtrs <> """
data """ <> name <> """
= """ <> enumCtrs <> """
instance eq""" <> vals.name <> """ :: Eq """ <> vals.name <> """ where
instance eq""" <> name <> """ :: Eq """ <> name <> """ where
eq = eq `on` show
instance ord""" <> vals.name <> """ :: Ord """ <> vals.name <> """ where
instance ord""" <> name <> """ :: Ord """ <> name <> """ where
compare = compare `on` show
instance argToGql""" <> vals.name <> """ :: ArgGql """ <> vals.name <> """ """ <> vals.name <> """
instance argToGql""" <> name <> """ :: ArgGql """ <> name <> """ """ <> name <> """
instance gqlArgString""" <> vals.name <> """ :: GqlArgString """ <> vals.name <> """ where
instance gqlArgString""" <> name <> """ :: GqlArgString """ <> name <> """ where
toGqlArgStringImpl a = snakeCase (show a)
instance decode""" <> vals.name <> """ :: Decode """ <> vals.name <> """ where
instance decode""" <> name <> """ :: Decode """ <> name <> """ where
decode a = decode a >>= case _ of
""" <> vals.decodeMember <> """
s -> fail $ ForeignError $ "Not a """ <> vals.name <> """: " <> s
""" <> decodeMember <> """
s -> fail $ ForeignError $ "Not a """ <> name <> """: " <> s
instance show""" <> vals.name <> """ :: Show """ <> vals.name <> """ where
instance show""" <> name <> """ :: Show """ <> name <> """ where
show a = case a of
""" <> vals.showMember <> """
""" <> showMember <> """
"""
where
vals =
{ name
, modulePrefix
, enumCtrs: intercalate "\n | " values
, decodeMember:
values
<#> (\v -> "\"" <> v <> "\" -> pure " <> v <> "")
# intercalate "\n "
, showMember:
values
<#> (\v -> "" <> v <> " -> \"" <> v <> "\"")
# intercalate "\n "
}
enumCtrs = intercalate "\n | " values
decodeMember =
values
<#> (\v -> " \"" <> v <> "\" -> pure " <> v <> "")
# intercalate "\n"
showMember =
values
<#> (\v -> " " <> v <> " -> \"" <> v <> "\"")
# intercalate "\n"

0 comments on commit 502c9af

Please sign in to comment.