teamwalnut / graphql-ppx

GraphQL language primitives for ReScript/ReasonML written in ReasonML
https://graphql-ppx.com
MIT License
257 stars 53 forks source link

Compatibilty with React-Relay? #247

Closed kleinspire closed 3 years ago

kleinspire commented 3 years ago

Hi,

I couldn't find React-Relay from the list of supported clients. I'd like to know how compatible is it with Relay knowing it has it's own set of graphql directives. I would probably have to write my own bindings for Relay, but I'm fine with that.

I'm already familiar with ReasonRelay, which is undoubtedly a great piece of work, but unfortunately it's a bit too opinionated for my taste.

jfrolich commented 3 years ago

Yes Relay bindings can be written that are compatible with graphql-ppx. It might need some extra features in the ppx. But it would be great to have that client in the ecosystem! I would like to move my codebase from Apollo to Relay as well, but it hasn't been a priority. Happy to assist on the ppx side if you are building bindings.

kleinspire commented 3 years ago

I'd like to use external Relay bindings directly with graphql-ppx generated graphql artifacts and types without using any intermediary library hiding React-Relay behind another interface.

Here's an example of what the bindings and usage of useFragment would ideally look like:

@module("react-relay/hooks")
external useFragment: (
  Graphql.fragmentNode<'node>,
  Graphql.fragmentRefs<'refs>,
) => 'unmasked = "useFragment"

module Fragment = %graphql(`
  fragment Component_Viewer on Viewer {
    name
  }
`)

@react.component
let make = (~viewerRefs: Graphql.fragmentRefs<[>#Component_Viewer]>) => {
  let {name}: Fragment.t = useFragment(Fragment.node, viewerRefs)
  ...
}