Skip to content

Commit ea3adfe

Browse files
authored
Merge pull request #143 from OxfordAbstracts/lower-case-symbols-only
Lower case symbols only
2 parents fe24db5 + 944e6bb commit ea3adfe

File tree

5 files changed

+94
-106
lines changed

5 files changed

+94
-106
lines changed

codegen/schema/src/GraphQL/Client/CodeGen/GetSymbols.purs

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Data.GraphQL.AST as AST
99
import Data.List (List, filter, foldMap, nub, sort, (:))
1010
import Data.Maybe (maybe)
1111
import Data.Newtype (unwrap)
12+
import Data.String as String
13+
import Data.String (toLower)
1214

1315
symbolsToCode :: forall f. Foldable f => String -> f String -> String
1416
symbolsToCode modulePrefix symbols =
@@ -24,15 +26,16 @@ import Type.Proxy (Proxy(..))
2426
symbols
2527
# Array.fromFoldable
2628
# Array.nub
29+
# Array.filter (lower1stChar && not keyword)
2730
# foldMap
28-
( \s -> "\n" <> s <> " = Proxy :: Proxy" <> show s
31+
( \s -> "\n" <> s <> " = Proxy :: Proxy " <> show s
2932
)
3033

3134
getSymbols :: AST.Document -> List String
3235
getSymbols doc =
3336
unwrap doc
3437
>>= definitionToSymbols
35-
# filter (not keyword)
38+
# filter (lower1stChar && not keyword)
3639
# nub
3740
# sort
3841
where
@@ -82,3 +85,8 @@ getSymbols doc =
8285

8386
keyword :: String -> Boolean
8487
keyword = flip elem [ "data", "type", "instance", "if", "then", "else" ]
88+
89+
lower1stChar :: String -> Boolean
90+
lower1stChar s = head == toLower head
91+
where
92+
head = String.take 1 s

codegen/schema/src/GraphQL/Client/CodeGen/SchemaCst.purs

+4-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Prelude
88
import Control.Monad.Writer (tell)
99
import Data.Array (elem)
1010
import Data.Array as Array
11-
import Data.CodePoint.Unicode (isLower)
1211
import Data.Filterable (class Filterable, filter)
1312
import Data.GraphQL.AST (NamedType)
1413
import Data.GraphQL.AST as AST
@@ -18,9 +17,8 @@ import Data.Map (Map, lookup)
1817
import Data.Map as Map
1918
import Data.Maybe (Maybe(..), maybe)
2019
import Data.Newtype (unwrap, wrap)
21-
import Data.String (codePointFromChar, toLower)
20+
import Data.String (toLower)
2221
import Data.String as String
23-
import Data.String.CodeUnits (charAt)
2422
import Data.String.Extra (pascalCase)
2523
import Data.Traversable (class Foldable, class Traversable, for, traverse)
2624
import Data.Tuple (Tuple(..))
@@ -29,13 +27,12 @@ import Data.Unfoldable (none)
2927
import GraphQL.Client.CodeGen.Types (InputOptions, GqlEnum)
3028
import GraphQL.Client.CodeGen.UtilCst (qualifiedTypeToName)
3129
import Partial.Unsafe (unsafePartial)
32-
import PureScript.CST.Types (ImportDecl, Module(..), ModuleHeader(..), ModuleName(..), Proper, QualifiedName)
30+
import PureScript.CST.Types (ImportDecl, Module(..), ModuleHeader(..), ModuleName, Proper, QualifiedName)
3331
import PureScript.CST.Types as CST
3432
import Tidy.Codegen (declDerive, declNewtype, declType, docComments, leading, lineComments, typeApp, typeArrow, typeCtor, typeRecord, typeRecordEmpty, typeRow, typeString, typeWildcard)
3533
import Tidy.Codegen.Class (class OverLeadingComments, toQualifiedName)
3634
import Tidy.Codegen.Monad (CodegenT, codegenModule, importFrom, importType)
3735
import Tidy.Util (nameOf)
38-
import Unsafe.Coerce (unsafeCoerce)
3936

4037
gqlToPursSchema :: InputOptions -> String -> String -> AST.Document -> Array GqlEnum -> Module Void
4138
gqlToPursSchema
@@ -192,7 +189,7 @@ gqlToPursSchema
192189
, argumentsDefinition
193190
, type: tipe
194191
}
195-
) = Tuple (safeFieldname name) case argumentsDefinition of
192+
) = Tuple name case argumentsDefinition of
196193
Nothing -> pursType
197194
Just def ->
198195
[ argumentsDefinitionToPurs objectName name def
@@ -224,7 +221,7 @@ gqlToPursSchema
224221
, name
225222
, type: tipe
226223
}
227-
) = Tuple (safeFieldname name) $ comment description
224+
) = Tuple name $ comment description
228225
case lookupOverride objectName name of
229226
Nothing -> argTypeToPurs objectName fieldName name tipe
230227
Just out -> case tipe of
@@ -465,14 +462,6 @@ getDefaultTypeNames { id, json, dateTime } = Map.fromFoldable
465462
, "bool" /\ qualify "Boolean"
466463
]
467464

468-
safeFieldname :: String -> String
469-
safeFieldname s = if isSafe then s else show s
470-
where
471-
isSafe =
472-
charAt 0 s
473-
# maybe false \c ->
474-
c == '_' || (isLower $ codePointFromChar c)
475-
476465
getTypeName :: AST.Type -> AST.NamedType
477466
getTypeName = case _ of
478467
AST.Type_NamedType n -> n

0 commit comments

Comments
 (0)