I have this GraphQL query:
mutation CreateBudget(
$revenue: Float!,
$hours: Int!,
$projectId: Int!,
) {
createBudget(
revenue: $revenue,
hours: $hours,
projectId: $projectId,
) {
id
}
}
For best practices, I want to use camelcase here, but snake_case in my database. The table looks like this:
CREATE TABLE IF NOT EXISTS `budgets` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`revenue` double(8,2) NOT NULL,
`hours` int(11) NOT NULL,
`project_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `budgets_project_id_foreign` (`project_id`),
CONSTRAINT `budgets_project_id_foreign` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
I use Lighthouse's @rename directive in order to convert between the casings. When running the query however, when submitting my query, some part of the code doesn't seem to recognise the project id, resulting in the following SQL error:
SQLSTATE[HY000]: General error: 1364 Field 'project_id' doesn't have a default value (SQL: insert into `budgets` (`revenue`, `hours`, `updated_at`, `created_at`) values (1200, 12, 2019-12-03 09:12:13, 2019-12-03 09:12:13))
The variables sent are
variables: {
revenue: 1200,
hours: 12,
projectId: 1
}
This is how my schema.graphql looks, using the @rename directive on the Budget type:
type Budget {
id: ID!
revenue: Float!
hours: Int!
projectId: Int! @rename(attribute: "project_id")
project: Project! @belongsTo
created_at: DateTime
updated_at: DateTime
}
type Mutation {
createBudget(
revenue: Float!
hours: Int!
projectId: Int!
): Budget @create(model: "App\\Models\\Budget\\Budget")
}
I must have overlooked something simple, but I can't seem to spot it. Anybody want to give it a shot?