zth / rescript-relay

Use Relay with ReScript.
https://rescript-relay-documentation.vercel.app/docs/getting-started
333 stars 49 forks source link

Consider hiding `.use` on `@inline` fragments #506

Closed ValdemarGr closed 2 months ago

ValdemarGr commented 2 months ago

Relay doesn't seem to handle InlineFrag.use(frag) well if the fragment module InlineFrag has the @inline directive. A strange error is thrown that makes finding the cause difficult, especially for new people.

This seems like a bug and has been an issue for longer that the linked to issue has been open.

Here is an example of the error:

Uncaught Invariant Violation: GraphQLTag: Expected a fragment, got `{"kind":"InlineDataFragment","name":"ContractSharedBookingByDateFrag"}`.
    invariant browser.js:38
    getFragment GraphQLTag.js:37
    useFragment_LEGACY useFragment.js:14
    useFragment useFragment.js:31
    useFragment2 RescriptRelay_Fragment.bs.js:10
    use$9 Contract_Shared.bs.js:298

I'm guessing this PPX code would have to be guarded by !hasInlineDirective.

zth commented 2 months ago

Definitely a good idea to hide. Do you want to take a stab at fixing it?

ValdemarGr commented 2 months ago

I opened a PR https://github.com/zth/rescript-relay/pull/507