graphql_ppx icon indicating copy to clipboard operation
graphql_ppx copied to clipboard

Return wrapped response for ReasonApollo

Open Gregoirevda opened this issue 5 years ago • 1 comments

Nice to have:

The ppx could return a wrapped ReasonApollo module, based on bs-config, to make the usage easier from reason-apollo:

module AddUser = [%graphql {| ... |} ];
//This could be avoided if the ppx would do this
module AddUserMutation = ReasonApollo.CreateMutation(AddUser);
...
<AddUserMutation>
...{(mutation) => <button onClick={() => {       
        // This is not obvious, this would also be fixed by providing a tighter coupling
        let addNewUserQuery = AddUser.make(~name="Bob", ());
       //                    ^^^^^^^^ should I use AddUser or AddUserMutation
       mutation(~variables=addNewUserQuery##variables,())
  }}> mutate</button>}
</AddUserMutation>

Gregoirevda avatar Jan 26 '19 00:01 Gregoirevda

I think it would make graphql_ppx coupled a lot with reason-apollo.

Another solution would be to provide the type of make function making it possible to alias that function in reason-apollo. That way AddUser would be only used to provide it to CreateMutation/CreateQuery/CreateSubscription and creating variables would be the responsibility of AddUserMutation which would be much cleaner for the users

baransu avatar Apr 03 '19 22:04 baransu