-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextra-fields-demo.go
More file actions
57 lines (53 loc) · 1.87 KB
/
extra-fields-demo.go
File metadata and controls
57 lines (53 loc) · 1.87 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package examples
// Example 1: Basic TypeExtraField - adds field only to types
/**
* @gqlType(name:"User")
* @gqlInput(name:"UserInput")
* @gqlTypeExtraField(name:"posts",type:"[Post!]!",description:"User's posts (only in type)")
* @gqlInputExtraField(name:"password",type:"String!",description:"Password (only in input)")
*/
type BasicUser struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
}
// Example 2: Using 'on' parameter to target specific types
/**
* @gqlType(name:"Article")
* @gqlType(name:"BlogPost")
* @gqlInput(name:"ArticleInput")
* @gqlTypeExtraField(name:"author",type:"User!",description:"Article author",on:"Article")
* @gqlTypeExtraField(name:"writer",type:"User!",description:"Blog writer",on:"BlogPost")
* @gqlTypeExtraField(name:"comments",type:"[Comment!]!",description:"All comments")
*/
type Content struct {
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
}
// Example 3: Using 'on' parameter to target specific inputs
/**
* @gqlType(name:"Product")
* @gqlInput(name:"CreateProductInput")
* @gqlInput(name:"UpdateProductInput")
* @gqlTypeExtraField(name:"reviews",type:"[Review!]!",description:"Product reviews")
* @gqlInputExtraField(name:"vendorId",type:"ID!",description:"Vendor ID (only in CreateProductInput)",on:"CreateProductInput")
*/
type ProductItem struct {
ID string `json:"id"`
Name string `json:"name"`
Price float64 `json:"price"`
}
// Example 4: Multiple 'on' targets
/**
* @gqlType(name:"Order")
* @gqlType(name:"Invoice")
* @gqlType(name:"Receipt")
* @gqlTypeExtraField(name:"customer",type:"User!",description:"Customer",on:"Order,Invoice")
* @gqlTypeExtraField(name:"total",type:"Float!",description:"Total amount")
*/
type Transaction struct {
ID string `json:"id"`
Amount float64 `json:"amount"`
Date string `json:"date"`
}