0.0.1-alpha.38 • Published 2 years ago

@futurelib/codegen v0.0.1-alpha.38

Weekly downloads
23
License
MIT
Repository
github
Last release
2 years ago

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.37

3 years ago

0.0.1-alpha.34

4 years ago

0.0.1-alpha.33

4 years ago

0.0.1-alpha.35

4 years ago

0.0.1-alpha.32

4 years ago

0.0.1-alpha.31

4 years ago

0.0.1-alpha.29

4 years ago

0.0.1-alpha.27

4 years ago

0.0.1-alpha.28

4 years ago

0.0.1-alpha.26

4 years ago

0.0.1-alpha.25

4 years ago