File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { CustomScalar , Scalar } from '@nestjs/graphql' ;
2
+ import { GraphQLError , Kind , ValueNode } from 'graphql' ;
3
+
4
+ @Scalar ( 'InlineMarkdown' )
5
+ export class InlineMarkdownScalar
6
+ implements CustomScalar < string , string | null >
7
+ {
8
+ description = 'A string that holds inline Markdown formatted text' ;
9
+
10
+ parseLiteral ( ast : ValueNode ) : string | null {
11
+ if ( ast . kind !== Kind . STRING ) {
12
+ throw new GraphQLError (
13
+ `Can only validate strings as InlineMarkdown but got a: ${ ast . kind } ` ,
14
+ ) ;
15
+ }
16
+ return ast . value ;
17
+ }
18
+ parseValue ( value : any ) {
19
+ return value ;
20
+ }
21
+ serialize ( value : any ) {
22
+ return value ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { CustomScalar } from '@nestjs/graphql';
3
3
import { GraphQLScalarType } from 'graphql' ;
4
4
import UploadScalar from 'graphql-upload/GraphQLUpload.mjs' ;
5
5
import { DateScalar , DateTimeScalar } from './luxon.graphql' ;
6
+ import { InlineMarkdownScalar } from './markdown.scalar' ;
6
7
import { RichTextScalar } from './rich-text.scalar' ;
7
8
import { UrlScalar } from './url.field' ;
8
9
@@ -15,4 +16,5 @@ export const getRegisteredScalars = (): Scalar[] => [
15
16
RichTextScalar ,
16
17
UploadScalar ,
17
18
UrlScalar ,
19
+ InlineMarkdownScalar ,
18
20
] ;
You can’t perform that action at this time.
0 commit comments