Skip to content

Is it possible to specify a type for scalar types during type generation? #1026

Answered by eysterbrian
ysfaran asked this question in Q&A
Discussion options

You must be logged in to vote

After looking into this same issue myself, it appears that asNexusMethod() takes a 3rd argument: sourceType?: SourceTypingDef.

Here's the full function declaration:
export declare function asNexusMethod<T extends GraphQLScalarType>(scalar: T, methodName: string, sourceType?: SourceTypingDef): T;

Digging into the types of SourceTypingDef, you can specify the generated TS type for a scalar by providing either: the type as a string; or an object that contains the module and export for the type (the TypingImport interface).

I think this code will generate what you're looking for (using resolvers from graphql-scalars):

export const GQLDate = asNexusMethod(GraphQLDateTime, 'dateTime', 'Date');
e…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ysfaran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants