Hi! I may be doing something wrong, but I can't make this to work.
I setup as the example, and when trying to create a new entry, an error from Postgres it's returned.
database model
export const Person = database.define('person', {
firstName: {
type: Sequelize.STRING,
allowNull: false,
},
lastName: {
type: Sequelize.STRING,
allowNull: false,
},
email: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isEmail: true,
},
},
});
export const Post = database.define('post', {
title: {
type: Sequelize.STRING,
allowNull: false,
},
content: {
type: Sequelize.TEXT,
allowNull: false,
},
});
Person.hasMany(Post);
Post.belongsTo(Person);
query
mutation addPost(
$content: String!,
$title: String!
)
{
createPost(
input: {
title: $title,
content: $content,
personId: 50
}
) {
newPost {
title
content
createdAt
}
}
}
variables
{
"title": "hola",
"content": "VVLV"
}
the error
(as-is)
{
"data": {
"createPost": null
},
"errors": [
{
"message": "la sintaxis de entrada no es válida para integer: «�»",
"locations": [
{
"line": 20,
"column": 3
}
],
"path": [
"createPost"
]
}
]
}
I'm new to GraphQL, but as I understand this is the way to do it. Sorry if this is not.
Thanks you!
Update: I try with SQLite, just to see if I was missing something, and still throwing errors.
{
"data": {
"createPost": null
},
"errors": [
{
"message": "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed",
"locations": [
{
"line": 31,
"column": 3
}
],
"path": [
"createPost"
]
}
]
}
It's clearer what's happening, but still, I don't know why it is happen.
UPDATE 2:
Looking in the Sequelize log:
Executing (default): INSERT INTO `posts` (`id`,`title`,`content`,`createdAt`,`updatedAt`,`personId`) VALUES (NULL,'hola','VVLV','2017-01-23 18:41:41.986 +00:00','2017-01-23 18:41:41.986 +00:00','�');
The personId
it's transformed in some unreadable code somewhere, both to humans and to the SQL interpreter, so it acts like no personId
it's provided.
According to the docs, the ID should not be human readable, but still be settable with both, string and integers values.
When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.