Skip to content

Commit e278673

Browse files
committed
rename type mapping to gqlScalarsToPursTypes for clarity #48
1 parent 9dfad58 commit e278673

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

codegen/schema/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Argument for generateSchema
1111
-- | Whether the schema should use newtypes. Necessary for circular/recursive schemas
1212
, useNewtypesForRecords :: Nullable Boolean
1313
-- | How to map graphQL types to Purescript types. The keys are graphql types and the values are purescript types you want them to be decoded as. Reasonable defaults are provided if you don't specify
14-
, gqlToPursTypes :: Nullable (Object String)
14+
, gqlScalarsToPursTypes :: Nullable (Object String)
1515
-- | Extra imports for the generated enums
1616
, enumImports :: Nullable (Array String)
1717
-- | Custom code to add to the generated enums
@@ -69,7 +69,7 @@ Argument for generateSchema
6969
-- | Whether the schema should use newtypes. Necessary for circular/recursive schemas
7070
, useNewtypesForRecords :: Nullable Boolean
7171
-- | How to map graphQL types to Purescript types. The keys are graphql types and the values are purescript types you want them to be decoded as. Reasonable defaults are provided if you don't specify
72-
, gqlToPursTypes :: Nullable (Object String)
72+
, gqlScalarsToPursTypes :: Nullable (Object String)
7373
-- | Extra imports for the generated enums
7474
, enumImports :: Nullable (Array String)
7575
-- | Custom code to add to the generated enums

examples/8-custom-gql-types/generate-purs-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = () =>
88
modulePath: ['Generated', 'Gql', 'Admin'],
99
useNewtypesForRecords: false,
1010
url: 'http://localhost:4000/graphql',
11-
gqlToPursTypes: {
11+
gqlScalarsToPursTypes: {
1212
GqlTypeThatIsAString: 'String',
1313
GqlTypeThatIsAnInt: 'Int'
1414
}

gen-schema-bundled.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GraphQL/Client/CodeGen/Js.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ schemasFromGqlToPursJs = mkFn2 go
2727
opts =
2828
{ externalTypes: Map.fromFoldableWithIndex (fromNullable mempty optsJs.externalTypes)
2929
, fieldTypeOverrides: Map.fromFoldableWithIndex <$> Map.fromFoldableWithIndex (fromNullable mempty optsJs.fieldTypeOverrides)
30-
, gqlToPursTypes: Map.fromFoldableWithIndex (fromNullable mempty optsJs.gqlToPursTypes)
30+
, gqlScalarsToPursTypes: Map.fromFoldableWithIndex (fromNullable mempty optsJs.gqlScalarsToPursTypes)
3131
, dir: fromNullable "" optsJs.dir
3232
, modulePath: fromNullable [] optsJs.modulePath
3333
, isHasura: fromNullable false optsJs.isHasura
@@ -53,7 +53,7 @@ fromNullable :: forall a. a -> Nullable a -> a
5353
fromNullable a = fromMaybe a <<< toMaybe
5454

5555
type InputOptionsJs
56-
= { gqlToPursTypes :: Nullable (Object String)
56+
= { gqlScalarsToPursTypes :: Nullable (Object String)
5757
, externalTypes ::
5858
Nullable
5959
( Object

src/GraphQL/Client/CodeGen/Schema.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ schemaFromGqlToPurs opts { schema, moduleName } =
117117
symbols = Array.fromFoldable $ getSymbols ast
118118
in
119119
{ mainSchemaCode: gqlToPursMainSchemaCode opts ast
120-
, enums: gqlToPursEnums opts.gqlToPursTypes ast
120+
, enums: gqlToPursEnums opts.gqlScalarsToPursTypes ast
121121
, symbols
122122
, moduleName
123123
}
@@ -141,7 +141,7 @@ toImport mainCode =
141141
)
142142

143143
gqlToPursMainSchemaCode :: InputOptions -> AST.Document -> String
144-
gqlToPursMainSchemaCode { gqlToPursTypes, externalTypes, fieldTypeOverrides, useNewtypesForRecords } doc =
144+
gqlToPursMainSchemaCode { gqlScalarsToPursTypes, externalTypes, fieldTypeOverrides, useNewtypesForRecords } doc =
145145
imports
146146
<> guard (imports /= "") "\n"
147147
<> "\n"
@@ -407,12 +407,12 @@ gqlToPursMainSchemaCode { gqlToPursTypes, externalTypes, fieldTypeOverrides, use
407407

408408
wrapArray s = "(Array " <> s <> ")"
409409

410-
typeName_ = typeName gqlToPursTypes
410+
typeName_ = typeName gqlScalarsToPursTypes
411411

412-
namedTypeToPurs_ = namedTypeToPurs gqlToPursTypes
412+
namedTypeToPurs_ = namedTypeToPurs gqlScalarsToPursTypes
413413

414414
gqlToPursEnums :: Map String String -> AST.Document -> Array GqlEnum
415-
gqlToPursEnums gqlToPursTypes = unwrap >>> mapMaybe definitionToEnum >>> Array.fromFoldable
415+
gqlToPursEnums gqlScalarsToPursTypes = unwrap >>> mapMaybe definitionToEnum >>> Array.fromFoldable
416416
where
417417
definitionToEnum :: AST.Definition -> Maybe GqlEnum
418418
definitionToEnum = case _ of
@@ -440,17 +440,17 @@ gqlToPursEnums gqlToPursTypes = unwrap >>> mapMaybe definitionToEnum >>> Array.f
440440
<#> \(AST.EnumValueDefinition { enumValue }) ->
441441
unwrap enumValue
442442

443-
typeName_ = typeName gqlToPursTypes
443+
typeName_ = typeName gqlScalarsToPursTypes
444444

445445
namedTypeToPurs :: Map String String -> AST.NamedType -> String
446-
namedTypeToPurs gqlToPursTypes (AST.NamedType str) = typeName gqlToPursTypes str
446+
namedTypeToPurs gqlScalarsToPursTypes (AST.NamedType str) = typeName gqlScalarsToPursTypes str
447447

448448
inlineComment :: Maybe String -> String
449449
inlineComment = foldMap (\str -> "\n{- " <> str <> " -}\n")
450450

451451
typeName :: Map String String -> String -> String
452-
typeName gqlToPursTypes str =
453-
lookup str gqlToPursTypes
452+
typeName gqlScalarsToPursTypes str =
453+
lookup str gqlScalarsToPursTypes
454454
# fromMaybe' \_ -> case pascalCase str of
455455
"Id" -> "ID"
456456
"Float" -> "Number"

src/GraphQL/Client/CodeGen/Types.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Effect (Effect)
2020
import Effect.Aff (Aff)
2121

2222
type InputOptions
23-
= { gqlToPursTypes :: Map String String
23+
= { gqlScalarsToPursTypes :: Map String String
2424
, externalTypes ::
2525
Map String
2626
{ moduleName :: String
@@ -54,7 +54,7 @@ type InputOptions
5454
defaultInputOptions :: InputOptions
5555
defaultInputOptions =
5656
{ externalTypes: Map.empty
57-
, gqlToPursTypes: Map.empty
57+
, gqlScalarsToPursTypes: Map.empty
5858
, fieldTypeOverrides: Map.empty
5959
, idImport: Nothing
6060
, dir: ""

test/GraphQL/Client/CodeGen/SchemaFromGqlToPurs.Test.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ instance argToGqlQuery :: (Newtype Query {| p}, RecordArg p a u) => ArgGql Quer
247247
` ( shouldParseToOpts
248248
{ dir: ""
249249
, cache: Nothing
250-
, gqlToPursTypes: Map.empty
250+
, gqlScalarsToPursTypes: Map.empty
251251
, useNewtypesForRecords: true
252252
, isHasura: false
253253
, modulePath: []
@@ -357,7 +357,7 @@ instance argToGqlX :: (Newtype X {| p}, RecordArg p a u) => ArgGql X { | a }"""
357357
shouldParseToOpts
358358
{ dir: ""
359359
, cache: Nothing
360-
, gqlToPursTypes: Map.empty
360+
, gqlScalarsToPursTypes: Map.empty
361361
, useNewtypesForRecords: true
362362
, isHasura: false
363363
, modulePath: []
@@ -372,7 +372,7 @@ instance argToGqlX :: (Newtype X {| p}, RecordArg p a u) => ArgGql X { | a }"""
372372
schemaFromGqlToPurs
373373
{ dir: ""
374374
, cache: Nothing
375-
, gqlToPursTypes: Map.empty
375+
, gqlScalarsToPursTypes: Map.empty
376376
, useNewtypesForRecords: true
377377
, isHasura: false
378378
, modulePath: []

0 commit comments

Comments
 (0)