[英]graphql 400 bad request - Must provide an operation
我試圖在Postman
中進行GraphQL
查詢,但它給出了 400 錯誤請求錯誤。
查詢是:
type Query {
school(id: ID, schoolCode: String): School
}
type School {
optionalSubjects: [String!]
code: ID!
defaultSubjects: String!
defaultExams: String!
}
我在這里錯過了什么? 我是 GraphQL 的新手,所以我不知道這個錯誤的原因。 我是否需要在GRAPHQL VARIABLES
部分下的 Postman 右側提供值?
問題出在錯誤中。 它說
必須提供一個操作
你正在做的是執行類型定義。 這就像在 typescript 中執行 function 接口定義而不是 function 本身。例如,我有一個類型定義
const Comment = new GraphQLObjectType({
name: "Comment",
fields: {
id: { type: new GraphQLNonNull(GraphQLID) },
content: { type: new GraphQLNonNull(GraphQLString) },
email: { type: new GraphQLNonNull(GraphQLString) },
createdAt: {
type: new GraphQLNonNull(GraphQLString),
resolve: (source) => source.createdAt.toISOString(),
},
postId: { type: new GraphQLNonNull(GraphQLID) },
},
});
其次是這個查詢
commentMainList: {
type: new GraphQLList(new GraphQLNonNull(Comment)),
resolve: async (source, args, { pgApi }) => {
return pgApi.commentMainList();
},
},
然后在 postman 我可以做
{
commentMainList{
id
postId
email
content
createdAt
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.