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?
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
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments