reasonml-community / reason-apollo-hooks

Deprecated in favor of https://github.com/reasonml-community/graphql-ppx
https://reasonml-community.github.io/reason-apollo-hooks/
MIT License
137 stars 28 forks source link

Type-safe useQuery #129

Open tsnobip opened 4 years ago

tsnobip commented 4 years ago

Right now, ~variables expects any type:

let useQuery:
  (
    ~client: ApolloClient.t=?,
    ~variables: 'raw_t_variables=?,
    ~notifyOnNetworkStatusChange: bool=?,
    ~fetchPolicy: ApolloHooksTypes.fetchPolicy=?,
    ~errorPolicy: ApolloHooksTypes.errorPolicy=?,
    ~skip: bool=?,
    ~pollInterval: int=?,
    ~context: Context.t=?,
    graphqlDefinition('t, 'raw_t)
  ) =>
  (variant('t), queryResult('t, 'raw_t, 'raw_t_variables))

So if you partially apply makeVariables by forgetting a non-optional argument for example, this won't be detected by the type-checker.

Any idea how to solve this?

jeddeloh commented 4 years ago

This should be resolved in both #117 and #122 branches. The variables arg is required and there are some convenience functions and Extension modules for making the ergonomics better.