forked from prismake/typegql
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschemaWithCustomDecorators.ts
More file actions
37 lines (32 loc) · 958 Bytes
/
schemaWithCustomDecorators.ts
File metadata and controls
37 lines (32 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SchemaRoot, Query, Field, ObjectType, compileSchema } from 'decapi'
function StringWithDescription(additionalDescription: string) {
return Field({
type: String,
description: `This is custom field. Additional description: ${additionalDescription}`
})
}
function ExplicitNameObjectType(name: string) {
if (!name) {
throw new Error(
`Classes decorated with @ExplicitNameObjectType require explicit name instead of one guessed from class name.`
)
}
return ObjectType({ name })
}
@ExplicitNameObjectType('MyTypeName')
class CustomObject {
@StringWithDescription('This is custom field')
stringValue: string
}
@SchemaRoot()
export class MySchemaCustomDecorators {
@Query()
getCustomObject(stringValue: string): CustomObject {
const object = new CustomObject()
object.stringValue = stringValue
return object
}
}
export const schemaWithCustomDecorators = compileSchema(
MySchemaCustomDecorators
)