first commit
This commit is contained in:
1
schema/.pydio
Normal file
1
schema/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
2600ef30-08cb-4fac-9bb4-d77c59b91d27
|
||||
78
schema/user.js
Normal file
78
schema/user.js
Normal file
@@ -0,0 +1,78 @@
|
||||
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
|
||||
})
|
||||
Reference in New Issue
Block a user