🌟 v3
This release migrates us to using @reasonml-community/graphql-ppx as our GraphQL PPX preprocessor of choice in lieu of @baransu/graphql_ppx_re. It also converts urql to a peerDependency of the library rather than bundling urql as a direct dependency. Finally, this release includes support for BuckleScript / ReScript > 8.0.0.
Changed
-
urql, along with its ownpeerDependencies, should be installed alongsidereason-urql, which no longer bundlesurqlas a direct dependency. See updated installation instructions in the README. PR by @parkerziegler here. -
Users should install
@reasonml-community/graphql-ppxas apeerDependencyofreason-urql. -
Users depending on
bs-platform>=8.0.0will need to specify a resolution forwonkav5 using yarn resolutions. See updated installation instructions in the README. -
Client.execute*methods underwent four major API changes:- There is no longer a
~requestlabelled argument. Instead, the GraphQL operation is passed using~queryforClient.executeQuery,~mutationforClient.executeMutation, and~subscriptionforClient.executeSubscription. This applies toClient.query,Client.mutation,Client.subscription, andClient.readQueryas well. - GraphQL operations are passed as first-class modules to
Client.execute*methods. This means you pass your entire GraphQL querymoduleas a function argument, like so:
open ReasonUrql; module GetAllDogs = [%graphql {| query getAllDogs { dogs { name breed likes } } |}]; /* Pass GetAllDogs as a first-class module to Client.executeQuery. */ Client.executeQuery(~query=(module GetAllDogs), ())
- Variables are passed as the last positional argument to
Client.execute*methods, if they are required. PR by @parkerziegler here. We interface with@reasonml-community/graphql-ppxto typecheck yourvariablesbased on the signature of your GraphQL operation. If your query, mutation, or subscription requires variables, pass them as a record in the last position, like so:
open ReasonUrql; module GetDog = [%graphql {| query getDog($key: ID!) { dog(key: $key) { name breed likes } } |}]; /* Pass GetDog as a first-class module to Client.executeQuery, with required variables as a record in the final position. */ Client.executeQuery(~query=(module GetDog), {key: "12345"})
- The
responsevariant forClient.execute*methods was renamed tooperationResponseand should be referenced from theTypesmodule rather than theClientmodule.
- There is no longer a
-
The hooks APIs underwent three major API changes:
- There is no longer a
~requestlabelled argument. Instead, the GraphQL operation is passed using~queryforuseQuery,~mutationforuseMutation, and~subscriptionforuseSubscription. - GraphQL operations are passed as first-class modules to each hook. This means you pass your entire GraphQL query
moduleas a function argument, like so:
open ReasonUrql; module GetAllDogs = [%graphql {| query getAllDogs { dogs { name breed likes } } |}]; [@react.component] let make = () => { /* Pass GetAllDogs as a first-class module to useQuery. */ let (Hooks.{response}, _) = Hooks.useQuery(~query=(module GetAllDogs), ()); /* Return the JSX for your component. */ }
- Variables are passed as the last positional argument to a hook, if they are required. PR by @amiralies here. We interface with
@reasonml-community/graphql-ppxto typecheck yourvariablesbased on the signature of your GraphQL operation. If your query, mutation, or subscription requires variables, pass them as a record in the last position, like so:
module GetDog = [%graphql {| query getDog($key: ID!) { dog(key: $key) { name breed likes } } |}]; [@react.component] let make = () => { /* Pass GetDog as a first-class module to useQuery, with required variables as a record in the final position. */ let (Hooks.{response}, _) = Hooks.useQuery(~query=(module GetDog), {key: "12345"}); /* Return the JSX for your component. */ }
- There is no longer a
Removed
- The
useDynamicMutationhook was removed.useMutationnow consolidates the former use case for this hook and brings our APIs more inline with howurqlworks.