GraphQLType
This commit is contained in:
@@ -160,10 +160,11 @@ func LoadItem(requestedFields []ast.Selection) (data []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自动生成 GraphQL 类型的函数
|
// 自动生成 GraphQL 类型的函数
|
||||||
func generateGraphQLType(model interface{}) (*graphql.Object, error) {
|
func GraphQLType(model interface{}) *graphql.Object {
|
||||||
modelType := reflect.TypeOf(model)
|
modelType := reflect.TypeOf(model)
|
||||||
if modelType.Kind() != reflect.Struct {
|
if modelType.Kind() != reflect.Struct {
|
||||||
return nil, fmt.Errorf("model must be a struct")
|
fmt.Println("输入的类型必须是结构体")
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fields := graphql.Fields{}
|
fields := graphql.Fields{}
|
||||||
@@ -189,7 +190,7 @@ func generateGraphQLType(model interface{}) (*graphql.Object, error) {
|
|||||||
return graphql.NewObject(graphql.ObjectConfig{
|
return graphql.NewObject(graphql.ObjectConfig{
|
||||||
Name: modelType.Name(),
|
Name: modelType.Name(),
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
}), nil
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断指定字段是否存在
|
// 判断指定字段是否存在
|
||||||
|
Reference in New Issue
Block a user