Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for @inline fragments #116

Closed
Arnarkari93 opened this issue Oct 23, 2020 · 13 comments
Closed

Support for @inline fragments #116

Arnarkari93 opened this issue Oct 23, 2020 · 13 comments

Comments

@Arnarkari93
Copy link
Contributor

Arnarkari93 commented Oct 23, 2020

How would reason-relay tackle supporting inline fragments? So non-react function can take advantage of data masking and getting correct reason types?

I tried binding it myself but was not successful since I could not find out how to get the module type that [%relay.fragment]

@zth
Copy link
Owner

zth commented Oct 23, 2020

@inline should work as-is now already, is it not? Or are you referring to readInlineData, which would allow you to read a fragment via a fragment ref outside of render/not via a hook?

@Arnarkari93
Copy link
Contributor Author

Yes, I am referring to readInlineData.

@zth
Copy link
Owner

zth commented Oct 23, 2020

Let me try and bind it real quick and get back to you... 😄

@Arnarkari93
Copy link
Contributor Author

This is as far as I got.

module type OperationType = {
   type fragment;
}

module type Operation = {
  type fragmentRef; 
  type operationType; 
  let node: ReasonRelay.fragmentNode;
  module Types: OperationType;
};

module ReadInlineData = (Operation: Operation) => {
  [@bs.module "react-relay"]
  external readInlineData:
    (ReasonRelay.fragmentNode, Operation.fragmentRef) => Operation.Types.fragment =
    "readInlineData";

  let read = (fragmentRef) => readInlineData(Operation.node, fragmentRef);
};

But I cant get type type ReasonRelay.fragmentRefs(|> Some fragment )

@zth
Copy link
Owner

zth commented Oct 23, 2020

I think what we should do isn't binding it in general, but rather generate code for it via the generated fragment module only when the fragment has @inline defined. So the API for using it would be roughly:

module Fragment =  [%relay.fragment {|
  fragment SomeUser_user on User @inline {
    ...
  }
|}];

let logData = user  => {
  SomeLoggingModule.log(Fragment.readInline(user));
);

Are you following how I'm thinking? I'll give it a try now and see if I can get it together real quick.

@Arnarkari93
Copy link
Contributor Author

Yes, I follow, so we need to add it in the ppx, that's where you lose me 😬

@Arnarkari93
Copy link
Contributor Author

I am not that comfortable adding it to ppx but I am willing to try.

@zth
Copy link
Owner

zth commented Oct 23, 2020

Give me a few minutes here and I'll have something you can review and hopefully get some insight on my thinking around adding stuff to the PPX, and then I can guide you through doing it yourself for the next feature we want to bind that touches the PPX, if you're interested?

@Arnarkari93
Copy link
Contributor Author

yes! very interested.

@zth
Copy link
Owner

zth commented Oct 23, 2020

Check this out: https://github.com/zth/reason-relay/compare/bind-read-inline

Is that making sense?

I haven't actually tested it yet so it might not work 😅

@zth
Copy link
Owner

zth commented Oct 23, 2020

...I'm making a few changes to that, bear with me a few more minutes.

@Arnarkari93
Copy link
Contributor Author

This looks good to me! Thank you for responding so quickly! I will try it out locally when I get a change.

@zth
Copy link
Owner

zth commented Oct 23, 2020

Implemented in #117

@zth zth closed this as completed Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants