简体   繁体   English

graphql 400 错误请求 - 必须提供操作

[英]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 右侧提供值?

  1. 400 bad request in graphql graphql 中的 400 个错误请求
  2. React Apollo GraphQL Mutation returns 400 (bad request) React Apollo GraphQL 突变返回 400(错误请求)
  3. Graphql POST call gives 400 bad request error Graphql POST 调用给出 400 错误请求错误

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM