I'm observing wierd behaviour with @json directive. I have an laravel application and Graphql calls are handled using nuwave/lighthouse. I have user table and one of the column in this table is json data which stores user hobbies in different language.
to be more precise:
column name: language_mapping
type: json
data structure: { hobbies : { en: "", de: "", da: ""}}
What is working?
Below update query works well and updates only specic language under hobbies.
GraphQL mutation:
mutation { updateLanguageSpecificUsers(user_id: 33, language_mapping: "hobbies.en=singing") {
language_mapping {
hobbies {
en
}
}
}
}
I understood that this line @json(columns: ["language_mapping"], model: Users) is responsible for updating the right key with the value.
Users.graphql file
extend type Mutation {
updateLanguageSpecificUsers(
language_mapping: Mixed
user_id: Int @rules(apply: ["numeric"])
): Users @json(columns: ["language_mapping"], model: Users) @update
}
What is not working?
I want to create an record if record not present else update the record if its present so, I created one more mutation for create or update but when I run the query, I'm getting "debugMessage": "Undefined index: id", "file": "/var/www/dummy/api/app/GraphQL/Directives/JsonDirective.php",
mutation {
updateOrCreateLanguageSpecificUsers(language_mapping: "hobbies.en=singing", user_id: 4171){
language_mapping {
hobbies {
en
}
}
}
}
Users.graphql file
extend type Mutation {
updateOrCreateLanguageSpecificUsers(
language_mapping: Mixed
user_id: Int @rules(apply: ["numeric"])
): Users @json(columns: ["language_mapping"], model: Users) @updateOrCreate(search: ["user_id"])
)
I couldn't understand whats going wrong in this mutation.
I would like to update or create based on presence of data.