Comments (13)
as blitz does not support graphql it would become out of hand to define and maintaining queries and their types in large project.
would be nice if blitz could auto generate queries using prisma somehow, something like https://gqless.dev
from blitz.
In server-side code, a query function can be called directly without useQuery
Does that mean there will be no option to cache queries on the server-side? We need data caching and SSR Suspense for our web app.
React Suspense with react-cache is also an option in the future - https://hackernoon.com/magic-of-react-suspense-with-concurrent-react-and-react-lazy-api-e32dc5f30ed1
from blitz.
@cr101 good question.
What type of caching do you need on the server? And do you need this for serverful or serverless deployment?
Blitz will definitely support SSR suspense — as soon as Next.js does, which I expect to be at or soon after the production release.
from blitz.
Does that mean there will be no option to cache queries on the server-side?
I would imagine that might be a good candidate for an optional middleware?
from blitz.
On the surface react-async-ssr
looks really nice! I am not sure without working through the details as to how much easier that would be to hook up with Next.js as opposed to doing a standard SSR query preload as whilst I would have to look at it to be sure, I am not sure we can easily override the actual renderToString routine to replace it with the async version. So far what I have managed to do was run queries and manually hydrate a custom global cache.
from blitz.
As far as this API is concerned this client-side cache invalidation stuff is getting complex. Could we possibly be straying away from the core premise of blitz that you should never need to worry about data fetching? I am wondering if we could merge queries into a resource if we would then get more automatic mileage in terms of cache invalidation after mutations as you could configure this is a resource and it's queries, mutations and cache could be linked? Thoughts? Perhaps the above API could be for advanced usage?
const productResource = createResource({
get: getProduct,
update: updateProduct,
create: createProduct,
delete: deleteProduct
});
export default function(props: {query: {id: number}}) {
const [product] = useResource(productResource.get({where: {id: props.query.id}}))
return (
<Formik
initialValues={product}
onSubmit={async values => {
try {
const product = await productResource.update(values)
} catch (error) {
alert('Error saving product')
}
}}>
{/* ... */}
</Formik>
)
}
I know this has echoes of the serverside rails controllers we had before.
from blitz.
Invalidating cache on route transitions is quite simple, yeah? And instead of requiring an opt-in, we could automatically invalidate cache on route transitions and then have an option to opt out.
refetch
and mutate
are for advanced cases.
Unless we enforce 100% SSR, then there's no way to get around client side cache. So the best we can do is make the common case extremely simple. I think a route transition will be the most common case.
from blitz.
SSR doesn't help with client side cache unless you mean full server rendered pages on every interaction which is not an option.
This could be a leaky abstraction if application developers don't change page routes after mutations. Think edit in place fields. Spreadsheets. Drag and drop interfaces. Not every app has a save button. The common case is crud interactions not route transitions. I think we need to link interactions to inform the way the cache works by default. Could be configuration doesn't matter how. Could even be convention inferred by cache key? ie. the path of the query method or the name of the interaction.
from blitz.
I'll think more about the cache stuff and report back later.
I realized something I overlooked: applying middleware in getServerSideProps
. Middleware can't be used in getStaticProps
because that is at build time without a request, but gSSP has req & res.
Here's what I'm thinking. Thoughts?
import {ssrQuery} from 'blitz'
import getProduct from '/app/products/queries/getProduct'
export const getServerSideProps = async ({params, req, res}) => {
const product = await ssrQuery(getProduct, {where: {id: params.id}}, {req, res}))
return {props: {product}}
}
export default function({product}) {
return <div>{product.name}</div>
}
Alternately, we could use a babel transform to add the req and res objects to the ssrQuery call so the user doesn't have to. But I don't really think that's a good idea.
from blitz.
The blitz generate
cli command will generate queries and mutations for you. From then on you only need to customize if needed. If this still doesn't provide good enough DX, then we can explore more things.
from blitz.
Will it be possible to query the database using raw queries via prisma.raw()?
from blitz.
@cr101, yes you bet! You have full access to prisma. The only thing we are planning to do for now is wrap the prisma CLI like blitz db migrate
. But in your code, you import prisma directly.
from blitz.
Closing as complete! I've added the documentation form here to the new docs website that will go live within a day or so.
I also opened #586 to discuss automatic cache invalidation.
from blitz.
Related Issues (20)
- can't locally silence [blitz-rpc] debug logs HOT 1
- deploy failed on vercel HOT 15
- Cannot find module 'next/dist/client/resolve-href' HOT 1
- BLITZ_PUBLIC_ prefix does not expose env to client HOT 2
- BlitzRoutes: Support app router HOT 4
- Windows Compatibility Issue: process.kill("SIGABRT") not supported HOT 5
- useAuthenticatedBlitzContext fails on vercel HOT 7
- getBlitzContext unusable in api HOT 2
- getBlitzContext() can't be use in edge funcion HOT 2
- nextjs (app router) fails on vercel HOT 1
- v2.0.7 `pnpm blitz dev --turbo` error with Invalid next.config.js options HOT 2
- enhancePrisma has disappeared since v2.0.7
- No matching version found for @blitzjs/[email protected] HOT 1
- useAuthenticatedBlitzContext doesn not populate next url param on redirect (app router)
- Allow override of "target" for ES2016+ features in Custom Server HOT 1
- ensure every page has `export const metadata`
- codemod at least has a typo, and maybe other problems HOT 4
- formik added when i pick final-form
- Blitz Auth: Blitz CTX session not populated in api route called from Next.js middleware
- When I use a client component in root layout the server returns a 500 error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blitz.