I'm trying to learn graphql
. I didn't find any good course witch will help me to learn it. So i started building it with little examples. In this moment i'm getting error when i'm trying to open http://127.0.0.1:3000/graphql
. it's telling me "message": "Must provide query string."
I thinks i did something wrong with my users query? This is my complete code of it. Can someone please help...
// user type
const UserType = new GraphQLObjectType({
name: "User",
description: "User Type",
fields: () => ({
id: { type: GraphQLInt },
firstname: { type: GraphQLString },
lastname: { type: GraphQLString },
email: { type: GraphQLString },
password: { type: GraphQLString },
}),
});
// register (mutation)
const register = {
type: UserType,
args: {
firstname: { type: GraphQLString },
lastname: { type: GraphQLString },
email: { type: GraphQLString },
password: { type: GraphQLString },
},
//@ts-ignore
async resolve(parent, args) {
const { firstname, lastname, email, password } = args;
const user = new User();
user.firstname = firstname;
user.lastname = lastname;
user.email = email;
user.password = password;
const result = await user.save();
console.log(result);
return result;
},
};
// users (query)
const users = {
// type: new GraphQLList(UserType),
type: UserType,
args: { id: { type: GraphQLInt } },
//@ts-ignore
async resolve(parent, args) {
const users = await User.find();
return users;
},
};
const MutationType = new GraphQLObjectType({
name: "MutationType",
description: "Mutations",
fields: { register },
});
const QueryType = new GraphQLObjectType({
name: "QueryType",
description: "Queries",
fields: { users },
});
const schema = new GraphQLSchema({ query: QueryType, mutation: MutationType });
app.use(
"/graphql",
graphqlHTTP({
schema,
graphiql: true,
})
);
I have 2 problems.
- when i type in browser:
http://127.0.0.1:3000/graphql
it's don't loading. it's telling me Loading... and stuck on it. - when i try it in insomnia it's telling me
{
"errors": [
{
"message": "Must provide query string."
}
]
}
how can i fixed it ?