Coder Social home page Coder Social logo

iamchenxin / relay-modern-hello-world Goto Github PK

View Code? Open in Web Editor NEW

This project forked from josephsavona/relay-modern-hello-world

0.0 2.0 0.0 117 KB

An basic app that loads one query with React and Relay Modern

Home Page: https://dev-blog.apollodata.com/exploring-relay-modern-276f5965f827

License: MIT License

JavaScript 97.95% HTML 1.97% CSS 0.07%

relay-modern-hello-world's Introduction

Relay Modern Hello World

This is a simple ejected create-react-app project with the minimal parts added to load a query with the Relay Modern release candidate. It calls a remote server that we use for a lot of example apps, the GitHunt app, which is like a clone of Product Hunt for GitHub repositories. You can get access to GraphiQL here, and the code for the server is available as well.

This example was prepared as part of an in-depth blog post about Relay Modern.

Running the app

yarn
yarn start

If you edit the query code, run the Relay Compiler:

yarn run relay
# or, to watch files and rerun
yarn run relay -- --watch

Code explanation

Here are the parts to look at:

This is the schema. We need this file to be passed into the relay-compiler.

This is a simple script I wrote up to introspect a remote server and save the schema in .graphql format.

Here we have added some scripts for the build process:

"relay": "relay-compiler --src ./src --schema schema.graphql",
"get-schema": "node scripts/getSchema.js"

We needed to install the babel-relay-plugin and add it to .babelrc:

{
  "presets": [
    "react-app"
  ],
  "plugins": [
    "relay"
  ]
}

This is the code that gets generated when you yarn run relay to run the Relay compiler. It's based on the query in App.js.

This file creates a Relay Environment and a Network instance that configures Relay with a function to fetch queries from the remote server.

This is the entirety of the application code, with the most important part being the QueryRenderer which calls Relay to inject data into the Feed component.

relay-modern-hello-world's People

Contributors

leoasis avatar

Watchers

James Cloos avatar  avatar

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.