You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
additionalHeader: "import _BigNumber from 'bignumber.js'",
175
+
})
176
+
```
177
+
178
+
> info **Hint** Alternatively, you can use a type reference instead, for example: `DateTime: Date`. In this case, `GraphQLDefinitionsFactory` will extract the name property of the specified type (`Date.name`) to generate TS definitions. Note: adding an import statement for non-built-in types (custom types) is required.
179
+
180
+
Now, given the following GraphQL custom scalar types:
181
+
182
+
```graphql
183
+
scalarDateTime
184
+
scalarBigNumber
185
+
scalarPayload
186
+
```
187
+
188
+
We will now see the following generated TypeScript definitions in `src/graphql.ts`:
189
+
190
+
```typescript
191
+
import_BigNumberfrom'bignumber.js'
192
+
193
+
exporttypeDateTime=Date
194
+
exporttypeBigNumber=_BigNumber
195
+
exporttypePayload=unknown
196
+
```
197
+
198
+
Here, we've used the `customScalarTypeMapping` property to supply a map of the types we wish to declare for our custom scalars. We've
199
+
also provided an `additionalHeader` property so that we can add any imports required for these type definitions. Lastly, we've added
200
+
a `defaultScalarType` of `'unknown'`, so that any custom scalars not specified in `customScalarTypeMapping` will be aliased to
201
+
`unknown` instead of `any` (which [TypeScript recommends](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type) using since 3.0 for added type safety).
202
+
203
+
> info **Hint** Note that we've imported `_BigNumber` from `bignumber.js`; this is to avoid [circular type references](https://github.com/Microsoft/TypeScript/issues/12525#issuecomment-263166239).
0 commit comments