# rivet-graphql **Repository Path**: mirrors_hashicorp/rivet-graphql ## Basic Information - **Project Name**: rivet-graphql - **Description**: A small, light, relay-like library for data fetching - **Primary Language**: Unknown - **License**: MPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2026-06-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README A small, light, [relay-like](https://relay.dev) library for data fetching. Relies on strong conventions in which components define their data needs. Rivet was built for and works best in a system in which you fetch all of your data **at the page level**, preferably in a single query, then pass down the data as needed to the components that use it. Below we'll take a tour of a sample implementation of Rivet within a React app, from bottom to top. We'll start with a small, simple component, move up to a larger, more complex component that uses the simple component as a dependency, then finally to a page that implements the more complex component. We'll start with the simple component, `Button`: ```jsx import fragment from './fragment.graphql' function Button({ title, url }) { return {title} } Button.fragmentSpec = { fragment } export default Button ``` And here's `fragment.graphql`, assuming that this setup uses a raw string loader for graphql files. This is not required and the graphql query can be used directly as a string within the component, but colocating allows for nice separation of concerns and better syntax highlighting. ```graphql fragment buttonFields on Button { title url } ``` The only unusual thing here is the fact that `Button` also defines a property called `fragmentSpec`. This property is an object, in this case with the key `fragment` set to be equal to the contents of the graphql file above. This allows higher levels to be aware of what data the button component needs, and ensure that it is properly fetched. > **NOTE**: As a matter of convention, we like to name all component fragments `Fields`. So, for example if you have a component called "Button", its fragment would be named `buttonFields`. For a component named "Docs Sidenav", its fragment would be `docsSidenavFields`. By keeping our naming consistent, it makes it easy for our team to write queries and debug errors. Let's move on to the next component. ```jsx import fragment from './fragment.graphql' import Button from '../button' function PersonAndButton({ person, button }) { return ( <>

Check out this cool person: {JSON.stringify(person)}