Skip to content

Commit 1cd61a2

Browse files
authored
Merge pull request #50 from OxfordAbstracts/allow-custom-type-mappings
Allow custom type mappings #48 #49
2 parents 1867e35 + e278673 commit 1cd61a2

File tree

19 files changed

+1990
-299
lines changed

19 files changed

+1990
-299
lines changed

codegen/schema/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Argument for generateSchema
1010
, modulePath :: Nullable (Array String)
1111
-- | Whether the schema should use newtypes. Necessary for circular/recursive schemas
1212
, useNewtypesForRecords :: Nullable Boolean
13+
-- | 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+
, gqlScalarsToPursTypes :: Nullable (Object String)
1315
-- | Extra imports for the generated enums
1416
, enumImports :: Nullable (Array String)
1517
-- | Custom code to add to the generated enums
@@ -66,6 +68,8 @@ Argument for generateSchema
6668
, modulePath :: Nullable (Array String)
6769
-- | Whether the schema should use newtypes. Necessary for circular/recursive schemas
6870
, useNewtypesForRecords :: Nullable Boolean
71+
-- | 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+
, gqlScalarsToPursTypes :: Nullable (Object String)
6973
-- | Extra imports for the generated enums
7074
, enumImports :: Nullable (Array String)
7175
-- | Custom code to add to the generated enums
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*
10+
/.spago
11+
/src/generated
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
A codegen example using custom graphQL types. Look in `generate-purs-schema.js` to
2+
see how types are mapped from graphQL to purescript.
3+
4+
Run `npm t` to see it in action
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// In your code replace this line with the npm package:
2+
// const { generateSchema } = require('purescript-graphql-client')
3+
const { generateSchema } = require('../../codegen/schema')
4+
5+
module.exports = () =>
6+
generateSchema({
7+
dir: './src/generated',
8+
modulePath: ['Generated', 'Gql', 'Admin'],
9+
useNewtypesForRecords: false,
10+
url: 'http://localhost:4000/graphql',
11+
gqlScalarsToPursTypes: {
12+
GqlTypeThatIsAString: 'String',
13+
GqlTypeThatIsAnInt: 'Int'
14+
}
15+
})

0 commit comments

Comments
 (0)