0.0.1-alpha.38 • Published 2 years ago
@futurelib/graphql-compiler v0.0.1-alpha.38
graphql-compiler
This is experimental and things might break badly if these packages are used
A prototype GraphQL compiler project for the web
Usage
import React from "react";
import { useFragment, useQuery, Selector } from "@futurelib/graphql-compiler";
import { createQueryLoader } from "@futurelib/graphql-compiler";
import getConfig from "next/config";
const { loadQuery } = createQueryLoader(
() => getConfig()?.serverRuntimeConfig.GRAPHQL_HOST
);
// Experimental Next.js feature running entirely on the server side
export async function unstable_getServerProps({ req, res, params }) {
const data = await loadQuery({ id: params.id });
return {
props: {
data
}
};
}
function Picture() {
const data = useFragment(`
on Picture {
src
}
`);
return <img src={src} />;
}
function Profile() {
const data = useFragment(`
on User {
name
picture {
${Picture}
}
}
`);
return (
<div>
<h1>{data.name}</h1>
<Selector path="picture">
<Picture />
</Selector>
</div>
);
}
function ProfilePage(props) {
const Provider = useQuery(`
query($id: ID!) {
profile(id: $id) {
${Profile}
}
}
`);
return (
<Provider data={props.data}>
<Selector path="user">
<Profile />
</Selector>
<PageFooter />
</Provider>
);
}
export default ProfilePage;
0.0.1-alpha.38
2 years ago
0.0.1-alpha.36
3 years ago
0.0.1-alpha.37
3 years ago
0.0.1-alpha.25
4 years ago
0.0.1-alpha.30
4 years ago
0.0.1-alpha.24
4 years ago
0.0.1-alpha.23
4 years ago
0.0.1-alpha.22
4 years ago
0.0.1-alpha.21
4 years ago
0.0.1-alpha.19
4 years ago
0.0.1-alpha.18
4 years ago
0.0.1-alpha.17
4 years ago
0.0.1-alpha.16
4 years ago
0.0.1-alpha.15
4 years ago
0.0.1-alpha.14
4 years ago
0.0.1-alpha.13
4 years ago
0.0.1-alpha.6
4 years ago
0.0.1-alpha.4
4 years ago
0.0.1-alpha.3
4 years ago
0.0.1-alpha.2
4 years ago
0.0.1-alpha.1
4 years ago
0.0.1-alpha.0
4 years ago