简体   繁体   中英

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.

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. Do I need to provide values on the right side of Postman under GRAPHQL VARIABLES section?

  1. 400 bad request in graphql
  2. React Apollo GraphQL Mutation returns 400 (bad request)
  3. Graphql POST call gives 400 bad request error

在此处输入图像描述

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

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

{
    commentMainList{
        id
        postId
        email
        content
        createdAt

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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