所以我最近一直在玩 Hotchocolate,我做了一个类(class),它给了我一份学生名单,但我想为它提供一些验证功能。我真的没有从 hotchocolate 官方网站上找到任何对我有帮助的东西。
学生.cs
public class Student
{
[GraphQLNonNullType]
public string Name{ get; set; }
[GraphQLNonNullType]
public string LastName{ get; set; }
[GraphQLNonNullType]
public string Picture { get; set; }
}
这是我的查询,它目前从列表中返回所有学生。学生查询.cs
public class StudentQuery
{
[UseFiltering]
[UseSorting]
public List<Student> GetStudents()
{
return MongoDBHelper.LoadRecords<Student>(EMongoCollection.Students);
}
}
现在我的问题是,我怎样才能为学生制定一个 ValidationRule,例如说一个学生的名字必须至少有 3 个字符?有人可以为我提供一些例子吗?
提前致谢。
最佳答案
HotChocolate 本身没有集成此类输入验证。
该框架仅进行 GraphQL 验证。所以检查无效的 GraphQL 查询。 (例如错误类型)
如果您想使用验证,有几个社区库可供选择:
此处列出了社区图书馆:
https://github.com/ChilliCream/hotchocolate/blob/main/COMMUNITY.md
关于c# - 使用 C# 进行热巧克力验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64495698/