Open rautenrieth-da opened 5 years ago
Same here, it seems the --passthroughCustomScalars
is unusable with typescript without an additional post-processing command.
In our case, a custom header would also be useful to add a eslint-disable
, since we use eslint
instead of tslint
This article https://www.leighhalliday.com/generating-types-apollo suggests using a global.d.ts
file to define the custom scalars type.
It works but it's still not ideal because I do not see a way to automatically do a conversion.
For example: type GQLDateTime = string
works (because I am converting dates to ISO strings on the server, but type GQLDateTime = Date
does not work.
I would like to define custom scalars and have their constructor or a deserialization function called when the data is received from the server.
In the back-end there exists a nice utility (https://www.npmjs.com/package/graphql-schema-typescript) which has:
customScalarType: {
DateTime: "Date",
MomentDateTime: "Moment"
},
importStatements: {
`import { Moment } from "moment";`
}
Which makes the development easier and more type secure. Is there anyway to implement something similar in apollo-tooling?
With
--passthroughCustomScalars
, the TypeScript codegen will generate files with unknown types for custom scalars, resulting in output that does not compile.To get my definition of those scalars into the codegen output, I am using
--customScalarsPrefix=CustomScalars.
and then using a shell script to add the following code at the top of the codegen output:To avoid this postprocessing step, can we add an option to prepend arbitrary content to the codegen output?