All Projects → zth → Rescript Relay

zth / Rescript Relay

Use Relay with ReasonML.

Programming Languages

reason
219 projects

Projects that are alternatives of or similar to Rescript Relay

Reason Graphql Fullstack
Fullstack Reason + GraphQL Todo List App
Stars: ✭ 246 (+14.95%)
Mutual labels:  graphql, reason-react, reasonml
Laravel Graphql
Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.
Stars: ✭ 1,793 (+737.85%)
Mutual labels:  graphql, relay
Absinthe relay
Absinthe support for the Relay framework
Stars: ✭ 143 (-33.18%)
Mutual labels:  graphql, relay
Fullstack Reason
A demo project that shows a fullstack ReasonML/OCaml app–native binary + webapp
Stars: ✭ 164 (-23.36%)
Mutual labels:  reason-react, reasonml
Reason Graphql
GraphQL server in pure Reason (Bucklescript)
Stars: ✭ 137 (-35.98%)
Mutual labels:  graphql, reasonml
Reason Apollo Hooks
Deprecated in favor of https://github.com/reasonml-community/graphql-ppx
Stars: ✭ 140 (-34.58%)
Mutual labels:  graphql, reasonml
Reactconfbr
Public infos and issues about React Conf Brasil organization
Stars: ✭ 156 (-27.1%)
Mutual labels:  graphql, relay
Graphql Sequelize Crud
Automatically generate queries and mutations from Sequelize models
Stars: ✭ 129 (-39.72%)
Mutual labels:  graphql, relay
Graphql Ppx
GraphQL language primitives for ReScript/ReasonML written in ReasonML
Stars: ✭ 185 (-13.55%)
Mutual labels:  graphql, reasonml
Bs Material Ui
ReScript bindings for material-ui
Stars: ✭ 185 (-13.55%)
Mutual labels:  reason-react, reasonml
Graphql.js
A Simple and Isomorphic GraphQL Client for JavaScript
Stars: ✭ 2,206 (+930.84%)
Mutual labels:  graphql, relay
Pure
React in pure Reason that targets native platforms.
Stars: ✭ 135 (-36.92%)
Mutual labels:  reason-react, reasonml
Frontend
🌏 The front-end application code for https://buildkite.com
Stars: ✭ 132 (-38.32%)
Mutual labels:  graphql, relay
Relay Rails Blog
A graphql, relay and standard rails application powered demo weblog. We are using Graphql server and relay for our react component data needs.
Stars: ✭ 140 (-34.58%)
Mutual labels:  graphql, relay
Graphbrainz
A fully-featured GraphQL interface for the MusicBrainz API.
Stars: ✭ 130 (-39.25%)
Mutual labels:  graphql, relay
Relay Authentication
An example app demonstrating role based authentication and file upload with Relay and GraphQL.
Stars: ✭ 153 (-28.5%)
Mutual labels:  graphql, relay
Django Graphql Auth
Django registration and authentication with GraphQL.
Stars: ✭ 200 (-6.54%)
Mutual labels:  graphql, relay
Brisk Reconciler
React.js-like reconciler implemented in OCaml/Reason
Stars: ✭ 124 (-42.06%)
Mutual labels:  reason-react, reasonml
Relay Example
[READONLY] 💝 Examples of common Relay patterns used in real-world applications. This repository is automatically exported from https://github.com/adeira/universe via Shipit
Stars: ✭ 126 (-41.12%)
Mutual labels:  graphql, relay
Awesome Graphql
Awesome list of GraphQL
Stars: ✭ 13,020 (+5984.11%)
Mutual labels:  graphql, relay

rescript-relay

Use Relay with ReScript/ReasonML.

Join our Discord

Getting started

Are you using version >= 0.13.0 and ReScript syntax with VSCode? Make sure you install our decicated VSCode extension. Note: It only works with ReScript syntax.

Check out the documentation.

Also, check out the changelog - things will continue change some between versions (including breaking changes, although we'll try and keep them to a minimum) as we iterate and reach a stable version.

What it looks like

Your components define what data they need through %relay().

/* Avatar.res */
module UserFragment = %relay(
  `
  fragment Avatar_user on User {
    firstName
    lastName
    avatarUrl
  }
`
)

@react.component
let make = (~user) => {
  let userData = UserFragment.use(user)

  <img
    className="avatar"
    src=userData.avatarUrl
    alt={
      userData.firstName ++ " "
      userData.lastName
    }
  />
}

Fragments can include other fragments. This allows you to break your UI into encapsulated components defining their own data demands.

Hooks to use your fragments are autogenerated for you. The hook needs a fragment reference from the GraphQL object where it was spread. Any object with one or more fragments spread on it will have a fragmentRefs prop on it, someObj.fragmentRefs. Pass that to the fragment hook.

Avatar_user is spread right on the fragment, so we pass userData.fragmentRefs to the <Avatar /> component since we know it'll contain the fragment ref for Avatar_user that <Avatar /> needs. The <Avatar /> component then uses that to get its data.

/* UserProfile.res */
module UserFragment = %relay(
  `
  fragment UserProfile_user on User {
    firstName
    lastName
    friendCount
    ...Avatar_user
  }
`
)

@react.component
let make = (~user) => {
  let userData = UserFragment.use(user)

  <div>
    <Avatar user=userData.fragmentRefs />
    <h1> {React.string(userData.firstName ++ (" " ++ userData.lastName))} </h1>
    <div>
      <p>
        {React.string(
          userData.firstName ++ (" has " ++ (userData.friendCount->string_of_int ++ " friends.")),
        )}
      </p>
    </div>
  </div>
}

Finally, you make a query using %relay() and include the fragments needed to render the entire tree of components.

/* Dashboard.res */
module Query = %relay(`
  query DashboardQuery {
    me {
      ...UserProfile_user
    }
  }
`)

@react.component
let make = () => {
  let queryData = Query.use(~variables=(), ())

  <div> <UserProfile user=queryData.me.fragmentRefs /> </div>
}

Examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].