facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.38k stars 1.82k forks source link

Add relay-config library #4780

Open robertf224 opened 3 weeks ago

robertf224 commented 3 weeks ago

Adding (or rather reviving) a relay-config library for loading/saving Relay configs. Will port babel-plugin-relay to use this but hitting "module not found" errors in tests.

captbaritone commented 4 days ago

Would love a more complete understanding of what problem(s) we're trying to solve here.

Here's what I'm inferring: The babel plugin currently needs to be able to see the Relay config file in order to apply the correct transformation. This requires:

  1. Locating the same config file that the compiler finds
  2. Parsing the config file in the same way the compiler does
  3. Validate the config file in the same way the compiler does
  4. Being able to have type-safe interactions with reading the config file once it's been validated

Am I correct in inferring that this is the set of problems we are trying to solve here?

robertf224 commented 4 days ago

@captbaritone yeah that's about right. For context I'm working on a nice integration layer right now between Relay and Next.js, but the same idea would apply to any tools building on top of Relay. The two places I'm using loadConfig are:

Providing a type-safe/standard library for loading Relay's config file will avoid bugs/hacks in tools building on top of Relay, e.g. see this cli that just hardcodes relay.config.json and then does a bunch of non-type-safe loading and manipulation on top

I will also port the Babel plugin to use this library in a follow-up!