react-starter-kit icon indicating copy to clipboard operation
react-starter-kit copied to clipboard

Relay.js integration.

Open pconcurrently opened this issue 10 years ago • 16 comments

Have you thought of setting up Relay.js for using GraphQL?

pconcurrently avatar Apr 09 '16 06:04 pconcurrently

Yep, I'm exporing this path.. at least, would be nice to have the GraphQL ednpoint compatible with Relay.

koistya avatar Apr 09 '16 06:04 koistya

Great, I'm trying to make Relay.js working on the starter kit as well. Hope that I can make a pull request soon.

pconcurrently avatar Apr 09 '16 07:04 pconcurrently

@shortgiraffe4 what do you think about this pattern of using Relay?

http://slides.com/koistya/universal-router#/9

koistya avatar Apr 09 '16 08:04 koistya

I am very interested in this idea. Apparently, I have observed that this implementation is kinda similar to what you are doing in react starter kit. Is that correct?

pconcurrently avatar Apr 11 '16 07:04 pconcurrently

Yep, correct. This approach uses a very simple algorithm (see universal-router/src/match.js) and promotes asynchronous code with ES2015 async/await syntax which tends to be easier to read and write as opposed to callbacks (used in React Router as an example).

koistya avatar Apr 11 '16 07:04 koistya

@koistya It seems to be that once relay is implemented components are not as reusable. They are heavily dependent on relay. Especially on the component level with this.props.relay. Do you find this to be true as well? Once relay is implemented this starter kit will only be able to work with relay and nothing else correct?

rterysen-openroad avatar May 10 '16 17:05 rterysen-openroad

@rterysen-openroad Reusable components still can be created. Relay container components should provide props to View components. View components should not be aware of Relay.

langpavel avatar May 10 '16 22:05 langpavel

@langpavel So this.props.relay will never be utilized in a view component?

rterysen-openroad avatar May 12 '16 14:05 rterysen-openroad

@rterysen-openroad You can always separate code of component to as many files as you wish, cannot you? If you wish design some component, e.g. DateTimePicker to be reusable, you always can. You can model props shape for this component and pass down only required data and event handlers. Relay drives data abstraction. If you use Redux as dependency, component will not be reusable without it as well. Doesn't matter which data backend you use.

Exactly. Do not use props.relay and your component can be then extracted and used in different project.

langpavel avatar May 12 '16 21:05 langpavel

@langpavel Thank you! I am going give this approach a try.

rterysen-openroad avatar May 12 '16 21:05 rterysen-openroad

:+1:

dhyegocalota avatar May 29 '16 22:05 dhyegocalota

Any progress?

pie6k avatar Aug 30 '16 10:08 pie6k

wait....

meodemsao avatar Oct 10 '16 08:10 meodemsao

I think with Relay, it makes a lot of sense to use declarative routes such as:

[
  {
    path: '/:username',
    component: './routes/UserProfile',
    queries: {
      viewer: 'query { viewer }',
      user: 'query { user(username: $username) }'
    }
  },
  ...
]

...where each route contains GraphQL root queries. You can see this solution implemented in react-static-boilerplate, though instead of Relay queries it uses custom queries compatible with REST API endpoints, but tweaking it to Relay should be very easy. Take a look:

  • /route.json - the list of routes in JSON (declarative)
  • /utils/routes-loader.js - Webpack loader that converts JSON routes to JavaScript code during compilation
  • /core/router.js - the router itself that has a single API method: const result = await Router.resolve(routes, location)
  • /main.js - application entry point, demonstrating how this router is used

Please upvote/downvote if you think this solution should be a part of the React Starter Kit.

koistya avatar Oct 10 '16 10:10 koistya

It would be great if you can add this to existing project. Can you make a branch for relay where you can just incorporate this to demonstrate how it works.

parthrao avatar Oct 14 '16 17:10 parthrao

@shortgiraffe4 thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.

NOTE: The main branch has been updated with React Starter Kit v2, using JAM-style architecture.

ulani avatar May 27 '21 20:05 ulani