JS Playground
A visual way to play with data from a GraphQL backend.

Creating a static page preview
Preview and download
Last updated
Was this helpful?
A visual way to play with data from a GraphQL backend.

Last updated
Was this helpful?
Was this helpful?
import React, { useEffect } from 'https://cdn.skypack.dev/[email protected]';
import ReactDOM from 'https://cdn.skypack.dev/[email protected]';
const MainComponent: React.FC = ({ children }) => {
return <div style={{
background: '#fff',
padding: 10
}}>
<div className="is-size-4 mb-4">Pizza pizza</div>
{children}
</div>
}
const PizzaSelector = Selector('Pizza')({
name: true,
description: true,
ingredients: {
name: true
},
price: true,
})
type PizzaType = FromSelector<typeof PizzaSelector,'Pizza'>
const Pizza: React.FC<PizzaType> = ({ name, ingredients, price,description }) => {
return <div className="box">
<div className="block"><strong className="mr-4">{name}</strong><i>{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(price)}</i></div>
<div className="block">{description}</div>
<div className="tags">
{ingredients.map(i => <div className="tag">{i.name}</div>)}
</div>
</div>
}
export const data = async () => {
const queryFetch = Gql("query")
const result = await queryFetch({
menu: {
pizzas: PizzaSelector
}
})
return result.menu.pizzas
}
type DataType = ReturnType<typeof data> extends Promise<infer R> ? R : ReturnType<typeof data>
export default (props: DataType) => {
return <MainComponent>{props.map(Pizza)}</MainComponent>
}