diff --git a/change/@graphitation-apollo-react-relay-duct-tape-0da64aa8-7f0d-4333-b1b4-9dff4b49f027.json b/change/@graphitation-apollo-react-relay-duct-tape-0da64aa8-7f0d-4333-b1b4-9dff4b49f027.json new file mode 100644 index 000000000..aa4265c8f --- /dev/null +++ b/change/@graphitation-apollo-react-relay-duct-tape-0da64aa8-7f0d-4333-b1b4-9dff4b49f027.json @@ -0,0 +1,7 @@ +{ + "type": "major", + "comment": "Align nova useMutation with Relay", + "packageName": "@graphitation/apollo-react-relay-duct-tape", + "email": "132382266+DarynaAkhmedova@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/examples/apollo-watch-fragments/src/useAddTodoMutation.ts b/examples/apollo-watch-fragments/src/useAddTodoMutation.ts index 47591e35f..179e995d2 100644 --- a/examples/apollo-watch-fragments/src/useAddTodoMutation.ts +++ b/examples/apollo-watch-fragments/src/useAddTodoMutation.ts @@ -1,5 +1,5 @@ import { useCallback } from "react"; -import { useMutation } from "@graphitation/apollo-react-relay-duct-tape"; +import { useMutation_depricated } from "@graphitation/apollo-react-relay-duct-tape"; import { graphql } from "@graphitation/graphql-js-tag"; import { useAddTodoMutation } from "./__generated__/useAddTodoMutation.graphql"; @@ -47,7 +47,7 @@ const mutation = graphql` // let tempID = 0; export function useAddTodoMutation() { - const [commit] = useMutation(mutation); + const [commit] = useMutation_depricated(mutation); return useCallback( (description: string) => { return commit({ diff --git a/packages/apollo-react-relay-duct-tape/package.json b/packages/apollo-react-relay-duct-tape/package.json index 8e89cddd3..e0050b953 100644 --- a/packages/apollo-react-relay-duct-tape/package.json +++ b/packages/apollo-react-relay-duct-tape/package.json @@ -30,6 +30,7 @@ "graphql": "^15.0.0", "monorepo-scripts": "*", "react": "^17.0.2", + "relay-hooks": "9.0.0", "@graphitation/apollo-react-relay-duct-tape-compiler": "^1.5.1", "ts-expect": "^1.3.0" }, diff --git a/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx b/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx index c0988509d..b414ac142 100644 --- a/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx +++ b/packages/apollo-react-relay-duct-tape/src/__tests__/hooks.test.tsx @@ -20,7 +20,7 @@ import { import { useFragment, useLazyLoadQuery, - useMutation, + useMutation_deprecated, useSubscription, } from "../hooks"; @@ -30,7 +30,7 @@ import { hooksTestFragment, hooksTestFragment$key, } from "./__generated__/hooksTestFragment.graphql"; -import { hooksTestMutation as hooksTestMutation$key } from "./__generated__/hooksTestMutation.graphql"; +import { hooksTestMutation, hooksTestMutation as hooksTestMutation$key } from "./__generated__/hooksTestMutation.graphql"; import { getOperationName } from "@apollo/client/utilities"; const schema = buildSchema( @@ -134,13 +134,13 @@ const SubscriptionComponent: React.FC = ({ return <>{children}; }; -const MutationComponent: React.FC<{ +const MutationComponentDeprecated: React.FC<{ variables: any; optimisticResponse: any; context?: any; }> = (props) => { const { variables, optimisticResponse, context } = props; - const [commit, isInFlight] = useMutation(mutation); + const [commit, isInFlight] = useMutation_deprecated(mutation); const [result, setResult] = React.useState(null); React.useEffect(() => { (async function () { @@ -357,11 +357,11 @@ describe(useSubscription, () => { }); }); -describe("useMutation", () => { - it("uses Apollo's useMutation hook", async () => { +describe("useMutation_deprecated", () => { + it("uses Apollo's useMutation_deprecated hook", async () => { const tree = createTestRenderer( - { act(() => { tree.update( - { context?: TMutationPayload["context"]; } -type MutationCommiter = ( +type MutationCommiter_deprecated = ( options: IMutationCommitterOptions, ) => Promise<{ errors?: Error[]; data?: TMutationPayload["response"] }>; @@ -301,9 +303,9 @@ type MutationCommiter = ( * @param mutation * @returns */ -export function useMutation( +export function useMutation_deprecated( mutation: GraphQLTaggedNode, -): [MutationCommiter, boolean] { +): [MutationCommiter_deprecated, boolean] { invariant( mutation?.__brand === undefined, "useMutation: Document must be a valid runtime type.", diff --git a/yarn.lock b/yarn.lock index 4d51fba6d..fc0ea03e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3054,6 +3054,13 @@ prop-types "^15.7.2" tslib "^2.3.0" +"@restart/hooks@^0.4.9": + version "0.4.16" + resolved "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.4.16.tgz#95ae8ac1cc7e2bd4fed5e39800ff85604c6d59fb" + integrity sha512-f7aCv7c+nU/3mF7NWLtVVr0Ra80RqsO89hO72r+Y/nvQr5+q0UFGkocElTH6MJApvReVh6JHUFYn2cw1WdHF3w== + dependencies: + dequal "^2.0.3" + "@rushstack/node-core-library@3.35.2": version "3.35.2" resolved "https://registry.yarnpkg.com/@rushstack/node-core-library/-/node-core-library-3.35.2.tgz#21ca879b5051a5ebafa952fafcd648a07a142bcb" @@ -5766,6 +5773,11 @@ dependency-graph@^0.11.0: resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.11.0.tgz#ac0ce7ed68a54da22165a85e97a01d53f5eb2e27" integrity sha512-JeMq7fEshyepOWDfcfHK06N3MhyPhz++vtqWhMT5O9A3K42rdsEDpfdVqjaqaAhsw6a+ZqeDvQVtD0hFHQWrzg== +dequal@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be" + integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA== + destroy@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015" @@ -6641,6 +6653,19 @@ fbjs@^3.0.0: setimmediate "^1.0.5" ua-parser-js "^0.7.18" +fbjs@^3.0.2: + version "3.0.5" + resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-3.0.5.tgz#aa0edb7d5caa6340011790bd9249dbef8a81128d" + integrity sha512-ztsSx77JBtkuMrEypfhgc3cI0+0h+svqeie7xHbh1k/IKdcydnvadp/mUaGgjAOXQmQSxsqgaRhS3q9fy+1kxg== + dependencies: + cross-fetch "^3.1.5" + fbjs-css-vars "^1.0.0" + loose-envify "^1.0.0" + object-assign "^4.1.0" + promise "^7.1.1" + setimmediate "^1.0.5" + ua-parser-js "^1.0.35" + figures@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" @@ -10809,6 +10834,14 @@ relay-compiler@12.0.0, relay-compiler@^12.0.0: signedsource "^1.0.0" yargs "^15.3.1" +relay-hooks@9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/relay-hooks/-/relay-hooks-9.0.0.tgz#3ee7f9e9b6de7c3440e2ca7d1c3ef3ddfcb0fb68" + integrity sha512-c0Pjnt8l+RFWFXBtRbQlp5FEo7jUEF9ESSJ0B3uz9s0EkW7n3+R+4OXusprmvZPaOPACISmd/yZlL88/wzQGmQ== + dependencies: + "@restart/hooks" "^0.4.9" + fbjs "^3.0.2" + relay-runtime@12.0.0: version "12.0.0" resolved "https://registry.yarnpkg.com/relay-runtime/-/relay-runtime-12.0.0.tgz#1e039282bdb5e0c1b9a7dc7f6b9a09d4f4ff8237" @@ -12224,6 +12257,11 @@ ua-parser-js@^0.7.18: resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.34.tgz#afb439e2e3e394bdc90080acb661a39c685b67d7" integrity sha512-cJMeh/eOILyGu0ejgTKB95yKT3zOenSe9UGE3vj6WfiOwgGYnmATUsnDixMFvdU+rNMvWih83hrUP8VwhF9yXQ== +ua-parser-js@^1.0.35: + version "1.0.39" + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.39.tgz#bfc07f361549bf249bd8f4589a4cccec18fd2018" + integrity sha512-k24RCVWlEcjkdOxYmVJgeD/0a1TiSpqLg+ZalVGV9lsnr4yqu0w7tX/x2xX6G4zpkgQnRf89lxuZ1wsbjXM8lw== + uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"