mhallin / graphql_ppx

GraphQL PPX rewriter for Bucklescript/ReasonML
BSD 3-Clause "New" or "Revised" License
320 stars 42 forks source link

Return wrapped response for ReasonApollo #70

Open Gregoirevda opened 5 years ago

Gregoirevda commented 5 years ago

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>
baransu commented 5 years ago

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