@@ -47,6 +47,7 @@ import Control.Lens
47
47
import Data.Aeson qualified as J
48
48
import Data.Aeson.Extended
49
49
import Data.Has
50
+ import Data.List.NonEmpty qualified as NE
50
51
import Data.Monoid
51
52
import Data.Text qualified as T
52
53
import Data.Text.Casing (GQLNameIdentifier (.. ))
@@ -121,20 +122,20 @@ parseNamingConventionFromText "graphql-default" = Right GraphqlCase
121
122
parseNamingConventionFromText _ = Left " naming_convention can either be \" hasura-default\" or \" graphql-default\" "
122
123
123
124
mkCustomizedTypename :: Maybe SourceTypeCustomization -> NamingCase -> MkTypename
124
- mkCustomizedTypename stc tCase = MkTypename ((applyTypeNameCaseCust tCase) . (applyTypeCust stc))
125
+ mkCustomizedTypename stc tCase = MkTypename ((applyTypeNameCaseCust tCase) . (applyTypeCust stc tCase ))
125
126
126
- mkCustomizedFieldName :: Maybe RootFieldsCustomization -> MkRootFieldName
127
- mkCustomizedFieldName rtc = MkRootFieldName (applyFieldCust rtc)
127
+ mkCustomizedFieldName :: Maybe RootFieldsCustomization -> NamingCase -> MkRootFieldName
128
+ mkCustomizedFieldName rtc tCase = MkRootFieldName (applyFieldCust rtc tCase )
128
129
129
130
-- | apply prefix and suffix to type name according to the source customization
130
- applyTypeCust :: Maybe SourceTypeCustomization -> (G. Name -> G. Name )
131
- applyTypeCust Nothing = id
132
- applyTypeCust (Just SourceTypeCustomization {.. }) = applyPrefixSuffix _stcPrefix _stcSuffix
131
+ applyTypeCust :: Maybe SourceTypeCustomization -> NamingCase -> (G. Name -> G. Name )
132
+ applyTypeCust Nothing _ = id
133
+ applyTypeCust (Just SourceTypeCustomization {.. }) tCase = applyPrefixSuffix _stcPrefix _stcSuffix tCase True
133
134
134
135
-- | apply prefix and suffix to field name according to the source customization
135
- applyFieldCust :: Maybe RootFieldsCustomization -> (G. Name -> G. Name )
136
- applyFieldCust Nothing = id
137
- applyFieldCust (Just RootFieldsCustomization {.. }) = applyPrefixSuffix _rootfcPrefix _rootfcSuffix
136
+ applyFieldCust :: Maybe RootFieldsCustomization -> NamingCase -> (G. Name -> G. Name )
137
+ applyFieldCust Nothing _ = id
138
+ applyFieldCust (Just RootFieldsCustomization {.. }) tCase = applyPrefixSuffix _rootfcPrefix _rootfcSuffix tCase False
138
139
139
140
-- | apply naming convention to type name
140
141
applyTypeNameCaseCust :: NamingCase -> G. Name -> G. Name
@@ -188,11 +189,20 @@ applyEnumValueCase tCase v = case tCase of
188
189
GraphqlCase -> C. transformNameWith (T. toUpper) v
189
190
190
191
-- | append/prepend the suffix/prefix in the graphql name
191
- applyPrefixSuffix :: Maybe G. Name -> Maybe G. Name -> G. Name -> G. Name
192
- applyPrefixSuffix Nothing Nothing name = name
193
- applyPrefixSuffix (Just prefix) Nothing name = prefix <> name
194
- applyPrefixSuffix Nothing (Just suffix) name = name <> suffix
195
- applyPrefixSuffix (Just prefix) (Just suffix) name = prefix <> name <> suffix
192
+ applyPrefixSuffix :: Maybe G. Name -> Maybe G. Name -> NamingCase -> Bool -> G. Name -> G. Name
193
+ applyPrefixSuffix Nothing Nothing tCase isTypeName name = concatPrefixSuffix tCase isTypeName $ NE. fromList [name]
194
+ applyPrefixSuffix (Just prefix) Nothing tCase isTypeName name = concatPrefixSuffix tCase isTypeName $ NE. fromList [prefix, name]
195
+ applyPrefixSuffix Nothing (Just suffix) tCase isTypeName name = concatPrefixSuffix tCase isTypeName $ NE. fromList [name, suffix]
196
+ applyPrefixSuffix (Just prefix) (Just suffix) tCase isTypeName name = concatPrefixSuffix tCase isTypeName $ NE. fromList [prefix, name, suffix]
197
+
198
+ concatPrefixSuffix :: NamingCase -> Bool -> NonEmpty G. Name -> G. Name
199
+ concatPrefixSuffix (HasuraCase ) _ neList = sconcat neList
200
+ concatPrefixSuffix (GraphqlCase ) isTypeName neList =
201
+ if isTypeName
202
+ then C. toPascalG prefixSuffixGQLIdent
203
+ else C. transformPrefixAndSuffixAndConcat prefixSuffixGQLIdent id C. upperFirstChar
204
+ where
205
+ prefixSuffixGQLIdent = C. fromNonEmptyList neList
196
206
197
207
data SourceCustomization = SourceCustomization
198
208
{ _scRootFields :: ! (Maybe RootFieldsCustomization ),
@@ -262,7 +272,7 @@ withSourceCustomization sc@SourceCustomization {..} namingConventionSupport defa
262
272
HasuraCase -> pure HasuraCase
263
273
264
274
withTypenameCustomization (mkCustomizedTypename _scTypeNames tCase)
265
- . withRootFieldNameCustomization (mkCustomizedFieldName _scRootFields)
275
+ . withRootFieldNameCustomization (mkCustomizedFieldName _scRootFields tCase )
266
276
. withNamingCaseCustomization tCase
267
277
$ m
268
278
0 commit comments