-
-
Notifications
You must be signed in to change notification settings - Fork 11
Description
π Pylonβs New Pages Router β Full-Stack Support Coming! Feedback Wanted! π
Iβm working on full-stack support for Pylon with a React Pages Router, similar to Next.js, bringing SSR & Hydration! π
πΉ Whatβs New?
β
Nested Pages with Layouts
β
Efficient SSR with Partial Data Fetching
β
Automatic Hydration with GQTYβs useQuery
β
PostCSS Support (e.g., TailwindCSS)
β
Full-Stack Development (frontend + backend, but keeping them separate)
π Project Structure
With the new Pages Router, your Pylon app structure looks like this:
pages/ # Frontend pages (outside src!)
βββ page.tsx # Root page ("/")
βββ layout.tsx # Root layout
βββ [slug]/ # Dynamic route (e.g., "/blog/:slug")
β βββ page.tsx # Page for dynamic route
β βββ layout.tsx # Layout for this route
src/ # Backend logic (GraphQL API)
βββ index.ts # Pylon backend logic
π οΈ Backend β src/index.ts (GraphQL API)
Pylon remains GraphQL-first β your backend logic lives in src/index.ts as usual.
import {app, usePages, PylonConfig} from '@getcronit/pylon'
export const graphql = {
Query: {
hello: () => {
return 'Hello, world!'
},
post: (slug: string) => {
return {title: `Post: ${slug}`, content: 'This is a blog post.'}
}
}
}
export const config: PylonConfig = {
plugins: [usePages()] // Enables the Pages Router
}
export default appπ Frontend β Pages Structure
1οΈβ£ Pages (pages/page.tsx)
Pages receive a data prop (from GQTYβs useQuery) and params from the URL.
import {PageProps} from '@getcronit/pylon'
const Page: React.FC<PageProps> = ({data}) => {
return (
<>
<title>{data.hello}</title>
<h1>{data.hello}</h1>
</>
)
}
export default Page2οΈβ£ Layouts (pages/layout.tsx)
Layouts wrap child pages and persist across navigation.
import {LayoutProps} from '@getcronit/pylon'
const Layout: React.FC<LayoutProps> = ({children}) => {
return (
<div>
<header>My App</header>
<main>{children}</main>
</div>
)
}
export default Layout3οΈβ£ Dynamic Routes (pages/[slug]/page.tsx)
The params object is used to pass dynamic values (e.g., /blog/my-post).
import {PageProps} from '@getcronit/pylon'
const Page: React.FC<PageProps> = ({data, params}) => {
return (
<>
<title>{data.post({slug: params.slug}).title}</title>
<h1>{data.post({slug: params.slug}).title}</h1>
<p>{data.post({slug: params.slug}).content}</p>
</>
)
}
export default Page4οΈβ£ Nested Layouts (pages/[slug]/layout.tsx)
Each route can have its own layout.
import {LayoutProps} from '@getcronit/pylon'
const BlogLayout: React.FC<LayoutProps> = ({children}) => {
return (
<div>
<aside>Blog Sidebar</aside>
<section>{children}</section>
</div>
)
}
export default BlogLayoutβ‘ How Data Fetching Works
πΉ During SSR, Pylon only fetches the fields used in the page.
πΉ This data is cached and sent to the client for hydration.
πΉ When new fields are accessed on the client, they are refetched dynamically.
This keeps API requests efficient and minimal while making development seamless!
π₯ Why This Matters
Unlike traditional full-stack frameworks, Pylon keeps GraphQL API and UI separate:
- GraphQL API remains clean and usable by other clients.
- Pages Router integrates seamlessly but does not mix backend logic inside components.
π‘ I Need Your Feedback!
This feature is under development, and Iβd love your input:
- Does this pages structure make sense?
- Would you use this for full-stack development?
- Any features or improvements youβd like to see?
Let me know what you think! π