From 0c5a1a7a735d57955f1051f76841b28c171c2c92 Mon Sep 17 00:00:00 2001 From: Christophe Rosset Date: Mon, 24 May 2021 13:54:24 +0200 Subject: [PATCH] feat(graphql): dont import from generated/graphql --- .eslintrc.js | 6 ++++++ .../AppOrganizationProfile/AppOrganizationProfile.tsx | 2 +- src/components/AppUserProfile/AppUserProfile.tsx | 2 +- src/components/TheOwnerProfile/TheOwnerProfile.tsx | 2 +- src/libs/graphql.tsx | 7 +++++++ src/pages/[owner].tsx | 2 +- src/utils/type-guards.ts | 2 +- 7 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/libs/graphql.tsx diff --git a/.eslintrc.js b/.eslintrc.js index 393df5b..f8d8663 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -65,5 +65,11 @@ module.exports = { peerDependencies: false, }, ], + "no-restricted-imports": [ + "error", + { + patterns: ["*/generated/graphql"], + }, + ], }, }; diff --git a/src/components/AppOrganizationProfile/AppOrganizationProfile.tsx b/src/components/AppOrganizationProfile/AppOrganizationProfile.tsx index 8f779ae..d0bdd6b 100644 --- a/src/components/AppOrganizationProfile/AppOrganizationProfile.tsx +++ b/src/components/AppOrganizationProfile/AppOrganizationProfile.tsx @@ -1,4 +1,4 @@ -import { Organization } from "../../generated/graphql"; +import { Organization } from "../../libs/graphql"; export type AppOrganizationProfileProps = { organization?: Organization; diff --git a/src/components/AppUserProfile/AppUserProfile.tsx b/src/components/AppUserProfile/AppUserProfile.tsx index 9d6fd7c..c72c71c 100644 --- a/src/components/AppUserProfile/AppUserProfile.tsx +++ b/src/components/AppUserProfile/AppUserProfile.tsx @@ -1,4 +1,4 @@ -import { User } from "../../generated/graphql"; +import { User } from "../../libs/graphql"; export type AppUserProfileProps = { user?: User; diff --git a/src/components/TheOwnerProfile/TheOwnerProfile.tsx b/src/components/TheOwnerProfile/TheOwnerProfile.tsx index a27a35c..dccbcc7 100644 --- a/src/components/TheOwnerProfile/TheOwnerProfile.tsx +++ b/src/components/TheOwnerProfile/TheOwnerProfile.tsx @@ -4,7 +4,7 @@ import { useGetRepositoryOwnerWithRepositoriesQuery, useGetProfileReadmeQuery, Blob, -} from "../../generated/graphql"; +} from "../../libs/graphql"; import { isUser, isOrganization } from "../../utils/type-guards"; import AppUserProfile from "../AppUserProfile/AppUserProfile"; import AppOrganizationProfile from "../AppOrganizationProfile/AppOrganizationProfile"; diff --git a/src/libs/graphql.tsx b/src/libs/graphql.tsx new file mode 100644 index 0000000..04deec3 --- /dev/null +++ b/src/libs/graphql.tsx @@ -0,0 +1,7 @@ +/* eslint-disable no-restricted-imports */ + +/** + * src/generated/graphql.tsx is generated with `npm run graphql-codegen` + * we don't import directly from the generated file in order to be able to make any overrides + */ +export * from "../generated/graphql"; diff --git a/src/pages/[owner].tsx b/src/pages/[owner].tsx index 8759b59..6bdcfaa 100644 --- a/src/pages/[owner].tsx +++ b/src/pages/[owner].tsx @@ -14,7 +14,7 @@ import { GetRepositoryOwnerWithRepositoriesDocument, GetProfileReadmeQuery, GetProfileReadmeDocument, -} from "../generated/graphql"; +} from "../libs/graphql"; import { isUser } from "../utils/type-guards"; import type { TheOwnerProfileProps } from "../components/TheOwnerProfile/TheOwnerProfile"; diff --git a/src/utils/type-guards.ts b/src/utils/type-guards.ts index cc828c9..8248b72 100644 --- a/src/utils/type-guards.ts +++ b/src/utils/type-guards.ts @@ -1,5 +1,5 @@ /* eslint-disable no-underscore-dangle */ -import { User, Organization } from "../generated/graphql"; +import { User, Organization } from "../libs/graphql"; /** * - Using type predicates: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates