johncmacy
johncmacy
XXata
Created by johncmacy on 9/25/2024 in #help
Error: Option apiKey is required in Remix loader
Hello, I've been trying to query from Xata in a Remix loader, and am getting this error.
Error: Option apiKey is required
at XataClient.parseOptions_fn
Error: Option apiKey is required
at XataClient.parseOptions_fn
I'm aware that queries should only be run on the server, but from what I understand, Remix loaders only run on the server, so I don't think that's the issue.
export async function loader() {
const xata = getXataClient()
const topics = await xata.db.topics.getAll()
return json({ topics })
}
export async function loader() {
const xata = getXataClient()
const topics = await xata.db.topics.getAll()
return json({ topics })
}
I found a workaround, which is to manually add apiKey and branch to the XataClient instance that is generated by the CLI.
export const getXataClient = () => {
if (instance) return instance

// change this
instance = new XataClient()
// to this
instance = new XataClient({
apiKey: process.env.XATA_API_KEY,
branch: process.env.XATA_BRANCH,
})

return instance
}
export const getXataClient = () => {
if (instance) return instance

// change this
instance = new XataClient()
// to this
instance = new XataClient({
apiKey: process.env.XATA_API_KEY,
branch: process.env.XATA_BRANCH,
})

return instance
}
But that means I have to manually do that every time I update the schema. Is there something obvious I'm missing? Thanks!
4 replies