W
Wasp-lang•4mo ago
prof_mark

An argument for 'context' was not provided.

I'm really struggling to understand this context that gets injected into api calls. I think I got all the configs straight (adding the right entities) in my main.wasp file, but I still get the context was not provided error message. How can I track down which part I am missing to make a call to an action get the context inlined?
5 Replies
kapa.ai
kapa.ai•4mo ago
Hi @prof_mark. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The context argument is automatically injected by Wasp when you call an action from the client. It contains user session information and information about entities. If you're calling an action from another action, you need to provide the context argument yourself. This can be a bit involved and unexpected, and Wasp is planning to provide easier ways to do this in the future [^1^]. If you're importing an action directly from its file, you'll need to construct the context completely on your own. However, if you import it via wasp/server/operations, you only need to pass the user to the context and the rest will be added [^5^]. To use an Entity in your Action, you need to add it to the action declaration in your Wasp file. Wasp will then inject the specified Entity into the Action's context argument, giving you access to the Entity's Prisma API [^7^]. If you're still having trouble, it might be helpful to check the initial error that made you think something was wrong with the context. This could give you a clue about what's missing [^2^]. Also, make sure you're importing the createProject operation correctly. It should be imported via wasp/client/operations [^1^]. [^1^]: https://discord.com/channels/686873244791210014/1218567315185209464 [^2^]: https://discord.com/channels/686873244791210014/1216119302244270181 [^5^]: https://github.com/wasp-lang/wasp/issues/1909 [^7^]: https://wasp-lang.dev/docs/data-model/operations/actions#using-entities-in-actions ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @prof_mark, 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?
prof_mark
prof_markOP•4mo ago
ok, I seem to have fixed this by moving my new action into the existing operations.ts file - I wanted to separate this action into a new file. is operations.ts a reserved file name? Also, does anyone think it would be worth to add "//autogenerated" to the top of all autogenerated files? This way I don't need to guess at what I can be editing and what is autogenerated?
Filip
Filip•4mo ago
Hey @prof_mark,
ok, I seem to have fixed this by moving my new action into the existing operations.ts file - I wanted to separate this action into a new file. is operations.ts a reserved file name?
This is strange, it should behave exactly the same regardless of the file name, and operations.ts is not reserved.
This way I don't need to guess at what I can be editing and what is autogenerated?
Which autogenerated files are you referring to? I don't think you should be seeing any of Wasp's autogenerated files. Are you sure you aren't editing code in the wrong place? Btw, can you share the code that throws the "context not available" message? Something strange is happening here 😄
prof_mark
prof_markOP•4mo ago
i cant remember the context not avaible bit, but the key thing i was not understanding is that
wasp/server/operations
wasp/server/operations
is a special place where all the actions and queries you define are collected. one can make new actions and queries in whatever files, bu then you import them from this special
wasp/server/operations
wasp/server/operations
place.
Filip
Filip•4mo ago
Oh, I see the confusion. This is because what you're importing isn't the function you defined. Instead, it's Wasp's wrapper that does some extra stuff for you.
Want results from more Discord servers?
Add your server