question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In Typescript, custom scalar types are emitted like:

export type Foo = any;

How can I make the emitted Foo refer to my existing types?

For example, if somewhere else in my code base, I have:

class Foo {
  bar: string

  someMethod() {
    ...
  }
}

I know this supports templating, but even with templating, I’m not sure how to make Foo in the generated types refer to my project’s Foo. It seems like I’d need to import existing scalar definitions into my schema template? Or I’d need to define all my custom scalars in templates? Both of these sound pretty unmaintainable. Is there some convenient way to do this? Or is there an example for solving this sort of problem?

PS. Thank you for this package!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:31 (11 by maintainers)

github_iconTop GitHub Comments

15reactions
dotansimhacommented, Feb 10, 2021

Is there an example on how to configure custom scalars mapping them to custom types? How do you specify where should the custom types be imported from?

You can use mappers format for scalars, we use it in other places as well, should look like that:

generates:
  types.ts:
    config:
      scalars:
        Date: "my-file#MyType"
    plugins:
      - typescript
4reactions
nandorojocommented, Oct 3, 2021

Is there an example on how to configure custom scalars mapping them to custom types? How do you specify where should the custom types be imported from?

You can use mappers format for scalars, we use it in other places as well, should look like that:

generates:
  types.ts:
    config:
      scalars:
        Date: "my-file#MyType"
    plugins:
      - typescript

@dotansimha I’m new to this plugin, could you share what my-file looks like?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom scalars - Apollo GraphQL Docs
Custom scalars. The GraphQL specification includes default scalar types Int , Float , String , Boolean , and ID ...
Read more >
Custom Scalars and Enums – GraphQL Tools
Add custom scalar and enum types to your graphql-tools generated schema.
Read more >
A library of custom GraphQL Scalars for creating ... - GitHub
A library of custom GraphQL scalar types for creating precise type-safe GraphQL schemas. Getting Started. Please refer to our website for all the...
Read more >
StepZen's Custom GraphQL Scalar Types
Built-in GraphQL Scalar Types ; Int: Signed 32‐bit integer. ; Float: Signed double-precision, floating-point value. ; String: UTF‐8 character sequence. ; Boolean: ...
Read more >
Custom Scalars - Lacinia - Read the Docs
Read about custom scalars. To define a custom scalar, you must provide implementations, in your schema, for two transforming callback functions: parse: parses ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found