[英]graphql 400 bad request - Must provide an operation
I am trying to hit a GraphQL
query in Postman
but it is giving 400 bad request error.我试图在
Postman
中进行GraphQL
查询,但它给出了 400 错误请求错误。
Query is:查询是:
type Query {
school(id: ID, schoolCode: String): School
}
type School {
optionalSubjects: [String!]
code: ID!
defaultSubjects: String!
defaultExams: String!
}
What am I missing here?我在这里错过了什么? I am new to GraphQL so I am not getting the cause of this error.
我是 GraphQL 的新手,所以我不知道这个错误的原因。 Do I need to provide values on the right side of Postman under
GRAPHQL VARIABLES
section?我是否需要在
GRAPHQL VARIABLES
部分下的 Postman 右侧提供值?
The problem is in the error.问题出在错误中。 It says
它说
Must provide an operation
必须提供一个操作
what you're doing is executing the type definition.你正在做的是执行类型定义。 That's like executing a function interface definition rather than the function itself in typescript. As an example, I have a type definition like
这就像在 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) },
},
});
followed by this query其次是这个查询
commentMainList: {
type: new GraphQLList(new GraphQLNonNull(Comment)),
resolve: async (source, args, { pgApi }) => {
return pgApi.commentMainList();
},
},
and then in postman I can do然后在 postman 我可以做
{
commentMainList{
id
postId
email
content
createdAt
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.