jeddeloh / rescript-apollo-client

ReScript bindings for the Apollo Client ecosystem
MIT License
126 stars 18 forks source link

Managing Local State #54

Closed idkjs closed 4 years ago

idkjs commented 4 years ago

What would be the equivalent in this project of this code:

const IS_LOGGED_IN = gql`
  query IsUserLoggedIn { 
   isLoggedIn @client 
 }`

It found in the apollo docs here-> https://www.apollographql.com/docs/tutorial/local-state/.

I guess this is a query on the client which we would set up with cache?

jeddeloh commented 4 years ago

Yes, assuming you've done the work of making it available in the cache you would use it just like normal:

[%graphql {|
  query IsUserLoggedIn { 
    isLoggedIn @client 
  }
|}]

The complication here is that you now need to account for this in your graphql_schema.json that graphql-ppx is consuming. We have some client state in our apps and I think I used some combination of graphql-tools and graphql-codegen to combine the schemas, but I don't know what would be best today. If you're just playing around, you could probably specify a separate schema for your client-only queries?

idkjs commented 4 years ago

oh wow. got an error before when i tried using @client. Seperate schema....I can see conceptually how we would do that. I am going to try that. Be nice to have an example of some of these less used cases in the repo or docs so if I get it done, I will share it if you want it. Thanks for the feedback, sir.

jfrolich commented 4 years ago

Hmm yes this would be interesting to implement within graphql-ppx. However, I don't know if many people use this feature. I certainly don't use it and I don't really see direct benefits of using this instead of simple client state with useState.