W
Wasp-lang4w ago
ayo

input coming back as undefined

Hi, I'm trying to implement a new action in, but my input args keep coming back as undefined. Here's is the flow I've followed from the docs curl eample:
curl -X POST http://localhost:3001/operations/follow-user \\
-H "Authorization: Bearer rwlvofoswke5w5naewjlrafuo5krkt5ulsgnpqcp" \\
-H "Content-Type: application/json" \\
-d '{"id":"599a3222-f137-4584-bea4-e327d48fef1f","followerId":"f2be6fba-7235-4d46-b630-77a638f1a825","followingId":"01959677-845f-4f4c-b886-4ca971d8d21","createdAt":"2024-10-28T21:23:34.371Z"}'
curl -X POST http://localhost:3001/operations/follow-user \\
-H "Authorization: Bearer rwlvofoswke5w5naewjlrafuo5krkt5ulsgnpqcp" \\
-H "Content-Type: application/json" \\
-d '{"id":"599a3222-f137-4584-bea4-e327d48fef1f","followerId":"f2be6fba-7235-4d46-b630-77a638f1a825","followingId":"01959677-845f-4f4c-b886-4ca971d8d21","createdAt":"2024-10-28T21:23:34.371Z"}'
main.wasp
action followUser {
fn: import { followUser } from "@src/user/operations",
entities: [User, Follow],
}
action followUser {
fn: import { followUser } from "@src/user/operations",
entities: [User, Follow],
}
@src/user/operations
import {
type FollowUser,
} from 'wasp/server/operations';

import { type User , Follow } from 'wasp/entities';

export const followUser: FollowUser<Pick<Follow, "followingId">, { success: boolean }> = async (
{ followingId } ,
context,
) => {console.log('followingId:', followingId);... prisma logic}
import {
type FollowUser,
} from 'wasp/server/operations';

import { type User , Follow } from 'wasp/entities';

export const followUser: FollowUser<Pick<Follow, "followingId">, { success: boolean }> = async (
{ followingId } ,
context,
) => {console.log('followingId:', followingId);... prisma logic}
std.out
followingId: undefined
followingId: undefined
6 Replies
kapa.ai
kapa.ai4w ago
Hi @ayo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your question and the knowledge sources available, I can offer some insights and suggestions regarding your issue with the followUser action in Wasp. The problem you're experiencing, where the input args are coming back as undefined, is likely related to how you're calling the action and passing the arguments. Let's break this down: 1. Action Declaration: Your action declaration in main.wasp looks correct:
action followUser {
fn: import { followUser } from "@src/user/operations",
entities: [User, Follow],
}
action followUser {
fn: import { followUser } from "@src/user/operations",
entities: [User, Follow],
}
2. Action Implementation: Your implementation in @src/user/operations also looks correct:
export const followUser: FollowUser<Pick<Follow, "followingId">, { success: boolean }> = async (
{ followingId } ,
context,
) => {console.log('followingId:', followingId);... prisma logic}
export const followUser: FollowUser<Pick<Follow, "followingId">, { success: boolean }> = async (
{ followingId } ,
context,
) => {console.log('followingId:', followingId);... prisma logic}
3. Calling the Action: The issue might be in how you're calling the action. According to the Wasp documentation on Actions (https://wasp-lang.dev/docs/data-model/operations/actions#using-actions), when you call an action, you should pass the arguments as a single object. Your curl example shows that you're passing multiple fields in the JSON payload:
{
"id":"599a3222-f137-4584-bea4-e327d48fef1f",
"followerId":"f2be6fba-7235-4d46-b630-77a638f1a825",
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21",
"createdAt":"2024-10-28T21:23:34.371Z"
}
{
"id":"599a3222-f137-4584-bea4-e327d48fef1f",
"followerId":"f2be6fba-7235-4d46-b630-77a638f1a825",
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21",
"createdAt":"2024-10-28T21:23:34.371Z"
}
However, your action implementation is only expecting followingId. This mismatch could be causing the issue. To fix this, you should modify your action call to only send the followingId:
{
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21"
}
{
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21"
}
If you need to pass more fields, you should update your action implementation to expect them:
export const followUser: FollowUser<Pick<Follow, "followingId" | "followerId">, { success: boolean }> = async (
{ followingId, followerId } ,
context,
) => {
console.log('followingId:', followingId);
console.log('followerId:', followerId);
// ... prisma logic
}
export const followUser: FollowUser<Pick<Follow, "followingId" | "followerId">, { success: boolean }> = async (
{ followingId, followerId } ,
context,
) => {
console.log('followingId:', followingId);
console.log('followerId:', followerId);
// ... prisma logic
}
Additionally, make sure you're importing and using the action correctly on the client side. If you're calling it from the client, you should import it from wasp/client/operations as mentioned in the Wasp documentation (https://wasp-lang.dev/docs/data-model/operations/actions#declaring-actions-in-wasp). If you're still experiencing issues after making these changes, you might want to double-check your server logs for any error messages, and ensure that your Wasp and Node.js versions are up to date. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ayo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ayo
ayoOP4w ago
I've also tried
{
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21"
}
{
"followingId":"01959677-845f-4f4c-b886-4ca971d8d21"
}
miho
miho4w ago
Using actions directly to cURL is not something we support i.e. we don't give you any docs on how to do it. If you check how actions' data is sent when they are invoked by the client you'll notice that the JSON payload is not exactly what you think it is. We are using SuperJSON to serialise the payload and it's wrapped in one extract object. {"json": <your-data>, "meta": <superjson-info>} You can just wrap it with "json" and leave out "meta" if you are not sending any Dates or other complex data types.
No description
ayo
ayoOP4w ago
Thank you for the response. That helped me get the feature going 🙌 . Also welcome back! cURL was just so I could provide an example here. I'm using bruno for endpoint testing
miho
miho4w ago
I'm glad you figured it out 👍 how's working with Bruno? I've heard about it, but didn't use it
ayo
ayoOP3w ago
Bruno I find pretty good. both in my 9-5 and on this project. Without needing enterprise version, I can do all I want
Want results from more Discord servers?
Add your server