Graphql GraphType使用ListGraphType或使用连接的第一个架构终结点
我正在为3种类型(比如学生、同学和宠物)设置端点,其中学生有很多同学和宠物。 我想出了两个选择:Graphql GraphType使用ListGraphType或使用连接的第一个架构终结点,graphql,graphql-dotnet,Graphql,Graphql Dotnet,我正在为3种类型(比如学生、同学和宠物)设置端点,其中学生有很多同学和宠物。 我想出了两个选择: 第一种方法是创建一个FriendsInterface,让同学和宠物实现该接口,然后将它们全部作为ListGraphType返回 第二个是创建与这些类型的连接:ClassmateConnection和PetConnection 我描述的第一种方法和第二种方法之间的区别是什么 创建连接是否更好(因为我可以看到API中允许分页的连接) 第二种方法是否会产生更好的GraphQL模式,其中每个Graph
- 第一种方法是创建一个FriendsInterface,让同学和宠物实现该接口,然后将它们全部作为ListGraphType返回
- 第二个是创建与这些类型的连接:ClassmateConnection和PetConnection
- 创建连接是否更好(因为我可以看到API中允许分页的连接)
- 第二种方法是否会产生更好的GraphQL模式,其中每个GraphQL节点通过一条边连接到另一个节点
Error message:
Error: Request failed with status code 400
at e.exports (http://localhost:3000/bundle.js:12:13653)
at e.exports (http://localhost:3000/bundle.js:44:1280)
at XMLHttpRequest.p.onreadystatechange (http://localhost:3000/bundle.js:12:12667)
第一种方法
public StudentType (MyData data) {
Name = "Student";
Description = "A curios creature in a giant universe.";
Field (d => d.Id).Description ("The id of the student.");
Field<ListGraphType<FriendInterface>> (
"friends",
resolve : context => data.GetFriends (context.Source)
);
}
在第二种方法中,查询如下:
student(studentID: "1") {
id
name
classmateConnection {
classmates {
id
}
}
petConnection {
pets {
id
}
}
}
student(studentID: "1") {
id
name
friends {
id
}
}
student(studentID: "1") {
id
name
classmateConnection {
classmates {
id
}
}
petConnection {
pets {
id
}
}
}