From 4cb056b34e9d958ac246bcf8cc5459ff9681f022 Mon Sep 17 00:00:00 2001 From: eric-burel Date: Thu, 15 Sep 2022 09:45:22 +0200 Subject: [PATCH] try to fix apollo by loading internals directly still don't work for related packages --- package.json | 2 +- packages/graphql/typings.ts | 2 +- packages/meteor-legacy/hooks/currentUser.ts | 2 +- packages/meteor-legacy/hooks/hooks.ts | 16 ++++++++++------ packages/react-hooks/create.ts | 3 ++- packages/react-hooks/delete.ts | 2 +- packages/react-hooks/multi.ts | 6 +++++- packages/react-hooks/single.ts | 4 ++-- packages/react-hooks/typings.ts | 2 +- packages/react-hooks/update.ts | 3 ++- packages/react-hooks/upsert.ts | 3 ++- starters/next/package.json | 4 +--- .../@vulcanjs/next-apollo/apolloClient.ts | 8 ++++---- 13 files changed, 33 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index c6e9ac80..3c900607 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "root", "private": true, "scripts": { - "postinstall": "node ./scripts/fix-apollo.js && ./scripts/copy-yarn-lock.sh", + "postinstall": "./scripts/copy-yarn-lock.sh", "prebuild": "yarn run clean:build", "build": "turbo run build build:types", "//build:pkg": "# Builds only packages, useful when running starters in dev mode", diff --git a/packages/graphql/typings.ts b/packages/graphql/typings.ts index 1ff2ddca..e4dc599f 100644 --- a/packages/graphql/typings.ts +++ b/packages/graphql/typings.ts @@ -1,5 +1,5 @@ import { VulcanModel } from "@vulcanjs/model"; -import { OperationVariables } from "@apollo/client"; +import type { OperationVariables } from "@apollo/client/core/index.js"; import { VulcanFieldSchema, VulcanSchema } from "@vulcanjs/schema"; import type { FilterableInput /*, VulcanCrudModel*/ } from "@vulcanjs/crud"; diff --git a/packages/meteor-legacy/hooks/currentUser.ts b/packages/meteor-legacy/hooks/currentUser.ts index 0e33f75b..74f8f979 100644 --- a/packages/meteor-legacy/hooks/currentUser.ts +++ b/packages/meteor-legacy/hooks/currentUser.ts @@ -1,4 +1,4 @@ -import { useQuery } from "@apollo/client"; +import { useQuery } from "@apollo/client/react/index.js"; import gql from "graphql-tag"; import get from "lodash/get.js"; diff --git a/packages/meteor-legacy/hooks/hooks.ts b/packages/meteor-legacy/hooks/hooks.ts index 9a45a53d..009bfdba 100644 --- a/packages/meteor-legacy/hooks/hooks.ts +++ b/packages/meteor-legacy/hooks/hooks.ts @@ -4,8 +4,8 @@ import { MutationTuple, MutationHookOptions, MutationFunctionOptions, - OperationVariables, -} from "@apollo/client"; +} from "@apollo/client/react/index.js"; +import type { OperationVariables } from "@apollo/client/core/index.js"; import gql from "graphql-tag"; import { ApolloVariables } from "@vulcanjs/graphql"; @@ -13,10 +13,14 @@ import { ApolloVariables } from "@vulcanjs/graphql"; // We modify the result function so that variables can be provided as first param, // which is more intuitive // Normal mutation function type (sadly not exported directly by Apollo) -type MutationFunction = - MutationTuple["0"]; -type MutationResult = - MutationTuple["1"]; +type MutationFunction< + TData = any, + TVariables = OperationVariables +> = MutationTuple["0"]; +type MutationResult< + TData = any, + TVariables = OperationVariables +> = MutationTuple["1"]; type MutationFunctionResult = ReturnType< MutationFunction diff --git a/packages/react-hooks/create.ts b/packages/react-hooks/create.ts index bd6970f7..c3c1a173 100644 --- a/packages/react-hooks/create.ts +++ b/packages/react-hooks/create.ts @@ -26,7 +26,8 @@ // */ -import { useMutation, MutationResult, FetchResult } from "@apollo/client"; +import { useMutation, MutationResult } from "@apollo/client/react/index.js"; +import type { FetchResult } from "@apollo/client/core/index.js"; import gql from "graphql-tag"; import { filterFunction } from "@vulcanjs/mongo/client"; diff --git a/packages/react-hooks/delete.ts b/packages/react-hooks/delete.ts index 7162a2d0..536a280c 100644 --- a/packages/react-hooks/delete.ts +++ b/packages/react-hooks/delete.ts @@ -26,7 +26,7 @@ */ -import { useMutation, MutationResult } from "@apollo/client"; +import { useMutation, MutationResult } from "@apollo/client/react/index.js"; import gql from "graphql-tag"; import { deleteClientTemplate, diff --git a/packages/react-hooks/multi.ts b/packages/react-hooks/multi.ts index 1a5b58dd..a79a86cc 100644 --- a/packages/react-hooks/multi.ts +++ b/packages/react-hooks/multi.ts @@ -11,7 +11,11 @@ Differences with Vulcan Meteor: */ import { DocumentNode } from "graphql"; -import { useQuery, QueryResult, QueryHookOptions } from "@apollo/client"; +import { + useQuery, + QueryResult, + QueryHookOptions, +} from "@apollo/client/react/index.js"; import { useState } from "react"; import { VulcanGraphqlModel, diff --git a/packages/react-hooks/single.ts b/packages/react-hooks/single.ts index e68caff2..4a712adf 100644 --- a/packages/react-hooks/single.ts +++ b/packages/react-hooks/single.ts @@ -14,11 +14,11 @@ import { import { computeQueryVariables } from "./variables"; import { - OperationVariables, useQuery, QueryResult, QueryHookOptions, -} from "@apollo/client"; +} from "@apollo/client/react/index.js"; +import type { OperationVariables } from "@apollo/client/core/index.js"; import gql from "graphql-tag"; const defaultInput = { diff --git a/packages/react-hooks/typings.ts b/packages/react-hooks/typings.ts index fde4f142..b5a7efb8 100644 --- a/packages/react-hooks/typings.ts +++ b/packages/react-hooks/typings.ts @@ -1,4 +1,4 @@ -import { MutationHookOptions } from "@apollo/client"; +import type { MutationHookOptions } from "@apollo/client/react/index.js"; import { Fragment, VulcanGraphqlModel } from "@vulcanjs/graphql"; export interface VulcanMutationHookOptions< diff --git a/packages/react-hooks/update.ts b/packages/react-hooks/update.ts index fcf62ed1..c0562140 100644 --- a/packages/react-hooks/update.ts +++ b/packages/react-hooks/update.ts @@ -27,7 +27,8 @@ // */ -import { useMutation, MutationResult, FetchResult } from "@apollo/client"; +import { useMutation, MutationResult } from "@apollo/client/react/index.js"; +import { FetchResult } from "@apollo/client/core/index.js"; import gql from "graphql-tag"; import { diff --git a/packages/react-hooks/upsert.ts b/packages/react-hooks/upsert.ts index bb6eb420..8aabc90d 100644 --- a/packages/react-hooks/upsert.ts +++ b/packages/react-hooks/upsert.ts @@ -27,7 +27,8 @@ */ -import { useMutation, MutationResult, FetchResult } from "@apollo/client"; +import { useMutation, MutationResult } from "@apollo/client/react/index.js"; +import type { FetchResult } from "@apollo/client/core/index.js"; import gql from "graphql-tag"; import { upsertClientTemplate } from "@vulcanjs/graphql"; diff --git a/starters/next/package.json b/starters/next/package.json index ad36442d..d03e0dbe 100644 --- a/starters/next/package.json +++ b/starters/next/package.json @@ -4,8 +4,6 @@ "private": true, "scripts": { "//----- DEVELOP -----": "", - "//_____Lifecycle_____": "", - "postinstall": "node ./.vn/scripts/fix-apollo.js", "//____Utilities_____": "", "clean": "rm -Rf ./dist ./storybook-static .yalc .next", "clean:next": "rm -Rf .next", @@ -24,7 +22,7 @@ "dev": "next", "//_____Build next app_____": "", "//prebuild": "# Temporary fix for https://github.com/vercel/next.js/issues/35110 and https://github.com/yarnpkg/berry/issues/1339#issuecomment-1136132035", - "prebuild": "(.vn/scripts/is-monorepo.js && rm -Rf ./node_modules/@vulcanjs && mkdir -p ./node_modules/@vulcanjs && cp -R ../../packages/* ./node_modules/@vulcanjs) || echo 'Not in the context of a monorepo, ok'", + "prebuild": "(node .vn/scripts/is-monorepo.js && echo 'in the context of a Monorepo, will clone local packages' && rm -Rf ./node_modules/@vulcanjs && mkdir -p ./node_modules/@vulcanjs && cp -R ../../packages/* ./node_modules/@vulcanjs) || echo 'Not in the context of a monorepo, ok'", "//build": "# Tip: on failure, we drop .next to avoid caching issue. Run 'prebuild' explicitely", "build": "yarn run prebuild && next build || (rm -Rf .next && exit 1) && yarn run postbuild", "postbuild": "next-sitemap --config vulcan-next-sitemap.js", diff --git a/starters/next/packages/@vulcanjs/next-apollo/apolloClient.ts b/starters/next/packages/@vulcanjs/next-apollo/apolloClient.ts index 895ff5b1..99ecc180 100644 --- a/starters/next/packages/@vulcanjs/next-apollo/apolloClient.ts +++ b/starters/next/packages/@vulcanjs/next-apollo/apolloClient.ts @@ -81,9 +81,9 @@ export function initializeApollo( } export function useApollo(initialState, options: CreateApolloClientOptions) { - const store = useMemo(() => initializeApollo(initialState, options), [ - initialState, - options, - ]); + const store = useMemo( + () => initializeApollo(initialState, options), + [initialState, options] + ); return store; }