images "total"
This commit is contained in:
		@@ -1181,6 +1181,23 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				existField := func(selections []ast.Selection, name string) bool {
 | 
			
		||||
					for _, field := range selections {
 | 
			
		||||
						if f, ok := field.(*ast.Field); ok && f.Name.Value == name {
 | 
			
		||||
							return true
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					return false
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if existField(p.Info.FieldASTs[0].SelectionSet.Selections, "total") {
 | 
			
		||||
					sql, _, _ := query.ToSQL()
 | 
			
		||||
					sql = strings.Replace(sql, "SELECT *", "SELECT COUNT(*)", 1)
 | 
			
		||||
					if err := db.Raw(sql).Scan(&total).Error; err != nil {
 | 
			
		||||
						return nil, err
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 如果没有外部排序则使用指定排序(正则sort只能是字母数字下划下)
 | 
			
		||||
				if p.Args["text"] == nil && p.Args["similar"] == nil && p.Args["interest"] == nil {
 | 
			
		||||
					sort := regexp.MustCompile(`[^a-zA-Z0-9_]`).ReplaceAllString(p.Args["sort"].(string), "")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user