я создаю приложение с graphQl с использованием узла js, но получаю ошибку, в которой говорится, что пользователи не являются конструкторами, вот мой код
const graphql = require('graphql')
const Users = require('../models/user')
const {
GraphQLObjectType,
GraphQLString,
GraphQLSchema,
GraphQLID,
GraphQLNonNull
} = graphql
const UserType = new GraphQLObjectType({
name: 'Users',
fields: () => ({
id: {
type: GraphQLID
},
username: {
type: GraphQLString
},
email: {
type: GraphQLString
}
})
})
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
args: {
id: {
type: GraphQLID
}
},
resolve(parent, args) {
return Users.findById(args.id)
}
}
}
})
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
register: {
type: UserType,
args: {
username: {
type: new GraphQLNonNull(GraphQLString)
},
email: {
type: new GraphQLNonNull(GraphQLString)
}
},
resolve(parent, args) {
let hUsers = new Users({
username: args.username,
email: args.email
})
return hUsers.save()
//.then((data) => {
// here is where i dont know how to proceed
// })
}
}
}
})
module.exports = new GraphQLSchema({
query: RootQuery,
mutation: Mutation
})
Я хочу создать страницу регистрации, где пользователи будутзарегистрироваться от.Я пытался протестировать его с Grahica, но я продолжаю получать эту ошибку «Пользователи не конструктор».Я не знаю, что делаю не так или как решить эту проблему.