在测试我们构建的graphql突变时,通过graphiql传递的价格整数值不会输入到字段中,而是包含一个空值。
这是针对与graphQL集成的SQL数据库的。
CREATE TABLE images
(
image_id SERIAL PRIMARY KEY,
title VARCHAR(50) NOT NULL,
description VARCHAR(200) NOT NULL,
display_name VARCHAR(50) NOT NULL,
posted_by VARCHAR(50) NOT NULL,
date_uploaded BIGINT,
price INT DEFAULT 0,
thumbnail_url TEXT NOT NULL,
obj_image_url TEXT NOT NULL,
format VARCHAR(20) NOT NULL,
likes INT DEFAULT 0,
category VARCHAR(50)
);
addImage: {
type: ImageType,
description: "Add an image",
args: {
title: { type: GraphQLNonNull(GraphQLString) },
description: { type: GraphQLNonNull(GraphQLString) },
display_name: { type: GraphQLNonNull(GraphQLString) },
posted_by: { type: GraphQLNonNull(GraphQLString) },
date_uploaded: { type: BigInt },
price: { type: GraphQLInt },
thumbnail_url: { type: GraphQLNonNull(GraphQLString) },
obj_image_url: { type: GraphQLNonNull(GraphQLString) },
format: { type: GraphQLString },
category: { type: GraphQLString }
},
resolve(parent, args) {
return db
.one(
"INSERT INTO images(title, description, display_name, posted_by, date_uploaded, price, thumbnail_url, obj_image_url, format, category) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *",
[
args.title,
args.description,
args.display_name,
args.posted_by,
args.date_uploaded,
args.price,
args.thumbnail_url,
args.obj_image_url,
args.format,
args.category
]
)
mutation {
addImage(title: "test",
description: "test",
display_name: "test", posted_by: "test",
price: 100,
thumbnail_url: "test",
obj_image_url: "test", format: "obj",
category: "test") {
title
image_id
date_uploaded
price
format
likes
category
}
}
期望价格字段填充为100,但是填充为空