Files
graphql/schema/user.js
2024-09-27 01:16:59 +08:00

78 lines
1.8 KiB
JavaScript

const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLList
} = require('graphql');
const db = require("../db");
const UserType = new GraphQLObjectType({
name: 'UserType',
fields: {
user_id: {
type: GraphQLInt
},
user_name: {
type: GraphQLString
},
user_pwd: {
type: GraphQLString
},
user_time: {
type: GraphQLString
},
user_money: {
type: GraphQLFloat
},
user_pic: {
type: GraphQLString
},
user_address: {
type: GraphQLString
},
user_phone: {
type: GraphQLString
}
}
})
const queryObj = new GraphQLObjectType({
name: 'UserApi',
description: '所有和用户相关的操作',
fields: {
getAllUser: {
description: '获取所有用户信息',
type: new GraphQLList(UserType),
async resolve(parent, args, request) {
return await db.Query({
sql: 'select * from user',
data: []
});
}
},
getOneUser: {
description: '获取单条用户信息',
type: UserType,
args: {
id: {
type: GraphQLInt,
defaultValue: 1
}
},
async resolve(parent, args, request) {
let data = await db.Query({
sql: 'select * from user where user_id = ?',
data: [args.id]
});
return data[0];
}
}
}
})
module.exports = new GraphQLSchema({
query: queryObj
})