Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Add shallow equal comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Feb 2, 2018
1 parent e716cfa commit badba88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/mutation.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/*
module PokemonMutation = [%graphql {|
mutation addPokemon($name: String!) {
addPokemon(name: $name) {
Expand Down Expand Up @@ -33,3 +33,4 @@ render: (_) => {
</Mutation>
}
};
*/
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
"graphql-tag": "^2.6.1",
"graphql_ppx": "^0.0.1",
"reason-react": "^0.3.1"
},
"dependencies": {
"fbjs": "^0.8.16"
}
}
6 changes: 5 additions & 1 deletion src/graphql-types/ReasonApolloQuery.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module type InternalConfig = {let apolloClient: ApolloClient.generatedApolloClie

module QueryFactory = (InternalConfig:InternalConfig) => {
external castResponse : string => {. "data": Js.Json.t } = "%identity";
external asJsObject : 'a => Js.t({..}) = "%identity";

[@bs.module] external gql : ReasonApolloTypes.gql = "graphql-tag";
[@bs.module] external shallowEqual : (Js.t({..}), Js.t({..})) => bool = "fbjs/lib/shallowEqual";


type response =
| Loading
Expand Down Expand Up @@ -62,7 +66,7 @@ module QueryFactory = (InternalConfig:InternalConfig) => {
})
},
willReceiveProps: ({state, reduce}) => {
if(q##variables != state.variables) {
if(!shallowEqual(asJsObject(q##variables), asJsObject(state.variables))) {
sendQuery(~query=q, ~reduce);
state;
} else {
Expand Down

0 comments on commit badba88

Please sign in to comment.