The data layer forNext.js

End-to-end typesafe data fetching for frontend teams at scale

Stop waiting for your backend team to update their APIs to match your needs, use Fuse.js to build a data layer that gives you control to fetch data exactly how you want

Video here

What's Fuse.js?

The best way to build a data layer

Fuse is an opinionated framework for creating fully type-safe data layers that allow frontend teams to translate resource-based APIs to their needs with the least amount of code necessary

// /types/BlogPost.ts
 
// Turn blog posts from your CMS into
// a GraphQL object type & query
export const BlogPostNode = node<BlogPostSource>({
  name: 'BlogPost',
  load: async (ids) => fetchBlogPosts(ids),
  fields: (t) => ({
    // Exose a field as-is
    title: t.exposeString('title'),
    // Rename a field
    content: t.exposeString('content_html'),
    // Connect it to other data
    author: t.field({
      type: UserNode,
      resolve: (blogPost) => blogPost.author_id
    })
  }),
})
// /components/BlogPost.tsx
 
const BlogPostFields = graphql(`
  fragment BlogPost_Fields on BlogPost {
    id
    title
    content
    author {
      # Combine fragments from other components to fetch the data they need
      ...UserCard_Fields
    }
  }
`)
 
export const BlogPost = (props: {
  blogPost: FragmentType<typeof BlogPostFields>
}) => {
  const blogPost = useFragment(BlogPostFields, props.blogPost)
 
  return (
    <div>
      {/* Fully type-safe, component-level data fetching */}
      <UserCard user={blogPost.author} />
      <h1>{blogPost.title}</h1>
      <RichText>{blogPost.content}</RichText>
    </div>
  )
}

Why Fuse.js?

Optimal data fetching out of the box

The best of the GraphQL ecosystem combined to give you optimal data fetching with a :chef-kiss: developer experience out of the box

  • Every page gets exactly, and only, the data it needs in a single network request
  • Data requirements are defined per component, which scales no matter how big your codebase gets
  • The whole API is documented and consistency enforced by the schema — no surprises

Powered by

Pothos

The schema builder for creating GraphQL schemas in typescript using a strongly typed code first approach.

URQL

Highly customizable and versatile GraphQL client, made to grow with your codebase.

GraphQL Yoga

The fully-featured GraphQL Server with focus on easy setup, performance and great developer experience.

Why a data layer?

Ship fast at scale

The fastest moving companies have a central data layer for frontend teams to translate resource-based APIs to user needs, which minimizes friction points with backend engineers.

However, this is not widely known. Most companies have backend engineers collaborate with frontend teams on APIs that work for the clients, which is a painfully slow process because backend engineers think in resources, but frontend teams need data shaped based on user needs.

Fuse.js's principles

  • Incrementally adoptable

    Start using Fuse.js for just one resource or microservice to try it out, no need to rewrite anything that's already working.

  • Pit of success

    Fuse.js has an opinionated design that makes it easy to do the right thing and hard to do the wrong thing to guide you and your team down the "pit of success."

  • Great developer experience

    In order to be adopted at scale, Fuse.js needs to have a great developer experience.

Who is behind Fuse.js?

Built by the team at Stellate

Fuse.js is made by the team at Stellate, the GraphQL CDN, which includes core team members and creators of some of the most popular open-source projects in the GraphQL ecosystem, including Prisma, the GraphQL Playground, GraphiQL, urql, Gatsby and others.