Code Monkey home page Code Monkey logo

cra-relay-typescript's Introduction

cra-relay-typescript

create-react-app logo Relay logo TypeScript logo TypeScript logo Tailwind CSS Logo

This is an example app for playing with Relay in Typescript create-react-app using https://rickandmortyapi.com/graphql

Why?

I wanted to use Relay in my Typescript CRA. for some sort of boilerplate/template/example to help me get started with Relay in my project. I wanted to use functional component and hooks but for most of the examples I stumbled upon had issues either they were not well maintained because they still are using class based components or in case of official relay hooks docs which are still experimental and are meant to be used with experimental concurrent mode. So after spending few hours researching I thought I should post an example that one can use a starting point to setup relay in there project that uses react-tools/relay-hooks(https://github.com/relay-tools/relay-hooks) which will in future allow one to migrate to official relay hooks.

Why not official relay hooks?

From what I understand, official relay hooks are meant to work best with experimental concurrent mode since they all require you to use Suspense and that means if I use that I need to use experimental version of React and Relay.

Hooks are now stable in relay@v11 and they use Suspense for data fetching.

Why relay-tools/relay-hooks?

From relay-tools/relay-hooks

It is a stable library and none of its dependencies is experimental and it allows you to immediately use react hooks with relay-runtime and it is designed for easy migration to react-relay hooks.

Setup

This is a typescript version of create react app. I just have my personal starter for CRA to ease the setup of eslint, github actions, vscode settings and more small things that I prefer to use. If you want you can just get started with npx create-react-app my-app --template typescript. For this example I have used @reach/router and TailwindCSS (for very very basic styling).

Some important dependencies:

  • get-graphql-schema: This is used to get the schema for your server and store it locally. This will be later used by relay-complier.
  • relay-compiler: Relay uses the Relay Compiler to convert GraphQL literals into generated files that live alongside source files.
  • relay-compiler-language-typescript: Language plugin for relay-compiler that allows us to create generated TypeScript files.
  • babel-plugin-relay: This macro allows us to use GraphQL template tag in our components.

Project Structure

  • src/components/relay: Set the relay-runtime environment.
  • src/components/global: Used as a wrapper to wrap the app. We set the RelayEnvironmentProvider from relay-hooks and provide Environment from src/components/relay.

Contributing/Help

If you find typos, have suggestions for me or something I did is confusing feel free to open an issue. If there are better ways to set Relay please let me know.

Helpful Resources

cra-relay-typescript's People

Contributors

dependabot[bot] avatar saihaj avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

amorim33

cra-relay-typescript's Issues

Broken demo

I think this is more gh-pages issue because of how homepage is set and all that. So I think I should deploy to surge/vercel
67E69484-7578-4D83-9B06-422C3A743AB9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.