JakeLoew
JakeLoew
WWasp-lang
Created by JakeLoew on 11/5/2024 in #🙋questions
Is there a way to inject env variables into wasp testing?
I have code that throws an error if a value from .env.server is not present. This code runs on the server. I can do something like MY_SECRET=abc123 wasp client test run, but I'm wondering if there's a way to do it within the wasp api.
13 replies
WWasp-lang
Created by JakeLoew on 9/30/2024 in #🙋questions
Client Side Routing
I'm using a custom deployment strategy for the server and client following this approach from the wasp documentation. I have various routes defined--/, /my-dashboard...etc. The pages render fine when you go to / and navigate to them via links on the page. However you get 404'd when trying to load https://my-site.com/my-dashboard, since they are SPA routes and there is no my-dashboard.html--i.e. they are not genuine html routes. I'm not sure how to specify that the site is a SPA using client routing.
9 replies
WWasp-lang
Created by JakeLoew on 9/18/2024 in #🙋questions
How to update data coming from `useQuery`
Let's say you have the following code in an app that has a model Author as well as model Book where each book belongs to one author...
import { getAuthor, createBook } from 'wasp/client/operations'

function MyComponent({ authorId }: { authorId: string; }) {
const { data: author } = useQuery(getAuthor, { id: authorId }) // populates author with books
const createNewBookByAuthor = async (authorId: number) => {
await createBook({ title: "new book!", authorId });
}

return <div>
<button onClick={createNewBookByAuthor}>Create New Book</button>
<ul>
{author.books.map(book => {
<li>
{book.title}
</li>
})}
</ul>
</div>
}
import { getAuthor, createBook } from 'wasp/client/operations'

function MyComponent({ authorId }: { authorId: string; }) {
const { data: author } = useQuery(getAuthor, { id: authorId }) // populates author with books
const createNewBookByAuthor = async (authorId: number) => {
await createBook({ title: "new book!", authorId });
}

return <div>
<button onClick={createNewBookByAuthor}>Create New Book</button>
<ul>
{author.books.map(book => {
<li>
{book.title}
</li>
})}
</ul>
</div>
}
What is a good pattern to update data coming from the getAuthor query when a new book is created?
12 replies
WWasp-lang
Created by JakeLoew on 8/8/2024 in #🙋questions
find-or-create with social login -- SaaS template
Using the SaaS template, is there a way to get a sort of find-or-create behavior from social login? Take this case, for example: I go to /signup and signup with GitHub. I have an email [email protected]. If I try to go to /login and log in with google, the existing user should be found and logged in, no? What I’m seeing is that I get an error: “Save failed: user with the same identity already exists”. Wasp v0.14.0
13 replies
WWasp-lang
Created by JakeLoew on 7/24/2024 in #🙋questions
useQuery error handling
I'm wondering why useQuery from wasp/client/operations doesn't handle errors as I expect. Consider the following:
// main.wasp
query getApplicationById {
fn: import { getApplicationById } from "@src/server/queries/getApplicationById.ts",
entities: [Application]
}
// main.wasp
query getApplicationById {
fn: import { getApplicationById } from "@src/server/queries/getApplicationById.ts",
entities: [Application]
}
// src/server/queries/getApplicationById.ts
import { Application } from 'wasp/entities';
export const getApplicationById: GetApplicationById<{ id: number }, Application> = async ({ id }, context) => {
throw new HttpError(404, 'Not found');
}
// src/server/queries/getApplicationById.ts
import { Application } from 'wasp/entities';
export const getApplicationById: GetApplicationById<{ id: number }, Application> = async ({ id }, context) => {
throw new HttpError(404, 'Not found');
}
// client/pages/ApplicationPage
function ApplicationPage() {
const { error, isError, status } = useQuery(getApplicationById, {
id: 1,
});

console.log({ isError, status });

return <div>{error?.message}</div>
}
// client/pages/ApplicationPage
function ApplicationPage() {
const { error, isError, status } = useQuery(getApplicationById, {
id: 1,
});

console.log({ isError, status });

return <div>{error?.message}</div>
}
The response from /operations-get-application-by-id is always 404, yet no error is returned from useQuery and isError is always false. status is "loading"
39 replies
WWasp-lang
Created by JakeLoew on 7/19/2024 in #🙋questions
migrate-dev failure when adding property to entity
Trying to perform a migration where I add an optional field to User, but since there already exist users in the DB the migration fails. For example: Migrating from:
entity User {=psl
id Int @id @default(autoincrement())
email String? @unique
psl=}
entity User {=psl
id Int @id @default(autoincrement())
email String? @unique
psl=}
To:
entity User {=psl
id Int @id @default(autoincrement())
email String? @unique
myField String?
psl=}
entity User {=psl
id Int @id @default(autoincrement())
email String? @unique
myField String?
psl=}
run wasp db migrate-dev Fails with
error TS2741: Property 'myField' is missing in type '{ email: string; }' but required in type 'Omit<GetResult<{ id: number; email: string; myField: string; }, unknown> & {}, "id">'.
error TS2741: Property 'myField' is missing in type '{ email: string; }' but required in type 'Omit<GetResult<{ id: number; email: string; myField: string; }, unknown> & {}, "id">'.
Wasp version: 0.13.2 (entities defined in main.wasp)
30 replies
WWasp-lang
Created by JakeLoew on 7/18/2024 in #🙋questions
Documentation for `login` action
No description
5 replies