diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 7dda58205..0cdd20f11 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -3,6 +3,7 @@ /* eslint-disable @typescript-eslint/no-namespace */ import "@cypress/code-coverage/support"; import { hasOperationName } from "../utils/graphql-test-utils"; +import { Operations } from "../../src/core/dbc-gateway/types"; const TOKEN_LIBRARY_KEY = "library"; const TOKEN_USER_KEY = "user"; @@ -26,12 +27,12 @@ Cypress.Commands.add("createFakeAuthenticatedSession", () => { /** * interceptGraphql is used to make a graphQLrequest that returns fixture data * - * @param {string} operationName The name of the operation to be mocked. + * @param {Operations} operationName The name of the operation to be mocked. * @param {string} fixtureFilePath The path to the fixture file to use as response * */ type InterceptGraphqlParams = { - operationName: string; + operationName: Operations; fixtureFilePath?: string; statusCode?: number; }; diff --git a/cypress/utils/graphql-test-utils.ts b/cypress/utils/graphql-test-utils.ts index a7d9609db..0ffea18e0 100644 --- a/cypress/utils/graphql-test-utils.ts +++ b/cypress/utils/graphql-test-utils.ts @@ -1,9 +1,10 @@ +import { Operations } from "../../src/core/dbc-gateway/types"; import { CyHttpMessages } from "../support/types/net-stubbing"; // Utility to match GraphQL mutation based on the operation name export const hasOperationName = ( req: CyHttpMessages.IncomingHttpRequest, - operationName: string + operationName: Operations ) => { const pattern = /(query|mutation) (\w+)[(]*/g; const matches = pattern.exec(req.body.query); @@ -13,7 +14,7 @@ export const hasOperationName = ( // Alias query if operationName matches export const aliasOperation = ( req: CyHttpMessages.IncomingHttpRequest, - operationName: string + operationName: Operations ) => { if (hasOperationName(req, operationName)) { const copyReq = req; diff --git a/dbc-gateway.codegen.yml b/dbc-gateway.codegen.yml index 6462c85d0..b71514fef 100644 --- a/dbc-gateway.codegen.yml +++ b/dbc-gateway.codegen.yml @@ -5,17 +5,20 @@ schema: Authorization: "Bearer ${STORYBOOK_LIBRARY_TOKEN}" documents: "src/**/*.graphql" generates: - src/core/dbc-gateway/generated/graphql.tsx: + src/core/dbc-gateway/generated/graphql.ts: config: fetcher: func: "../graphql-fetcher#fetcher" namingConvention: "./scripts/dbc-gateway.codegen.naming" defaultScalarType: unknown + identifierName: operationNames + useConsts: true legacyMode: true plugins: - "typescript" - "typescript-operations" - "typescript-react-query" + - "named-operations-object" hooks: afterOneFileWrite: - yarn post-process-generated-graphql diff --git a/package.json b/package.json index 727154294..e19046866 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "@graphql-codegen/add": "^5.0.3", "@graphql-codegen/cli": "^5.0.3", "@graphql-codegen/introspection": "^4.0.3", + "@graphql-codegen/named-operations-object": "^3.1.0", "@graphql-codegen/typescript": "^4.1.1", "@graphql-codegen/typescript-graphql-files-modules": "^3.0.0", "@graphql-codegen/typescript-operations": "^4.3.1", diff --git a/src/core/dbc-gateway/generated/graphql.tsx b/src/core/dbc-gateway/generated/graphql.ts similarity index 99% rename from src/core/dbc-gateway/generated/graphql.tsx rename to src/core/dbc-gateway/generated/graphql.ts index 765d91dc0..c30be1b57 100644 --- a/src/core/dbc-gateway/generated/graphql.tsx +++ b/src/core/dbc-gateway/generated/graphql.ts @@ -7468,3 +7468,41 @@ export const usePlaceCopyMutation = ( options ); }; + +export const operationNames = { + Query: { + getSmallWork: "getSmallWork" as const, + getManifestationViaMaterialByFaust: + "getManifestationViaMaterialByFaust" as const, + getManifestationViaBestRepresentationByFaust: + "getManifestationViaBestRepresentationByFaust" as const, + getMaterial: "getMaterial" as const, + getMaterialGlobally: "getMaterialGlobally" as const, + getInfomedia: "getInfomedia" as const, + getReviewManifestations: "getReviewManifestations" as const, + recommendFromFaust: "recommendFromFaust" as const, + searchWithPagination: "searchWithPagination" as const, + complexSearchWithPaginationWorkAccess: + "complexSearchWithPaginationWorkAccess" as const, + complexSearchWithPagination: "complexSearchWithPagination" as const, + suggestionsFromQueryString: "suggestionsFromQueryString" as const, + searchFacet: "searchFacet" as const, + intelligentFacets: "intelligentFacets" as const + }, + Mutation: { + openOrder: "openOrder" as const, + placeCopy: "placeCopy" as const + }, + Fragment: { + ManifestationBasicDetails: "ManifestationBasicDetails" as const, + ManifestationsSimple: "ManifestationsSimple" as const, + ManifestationsAccess: "ManifestationsAccess" as const, + ManifestationsSimpleFields: "ManifestationsSimpleFields" as const, + ManifestationReviewFields: "ManifestationReviewFields" as const, + SeriesSimple: "SeriesSimple" as const, + WorkAccess: "WorkAccess" as const, + WorkSmall: "WorkSmall" as const, + WorkMedium: "WorkMedium" as const, + WithLanguages: "WithLanguages" as const + } +}; diff --git a/src/core/dbc-gateway/types.ts b/src/core/dbc-gateway/types.ts new file mode 100644 index 000000000..5dc68751d --- /dev/null +++ b/src/core/dbc-gateway/types.ts @@ -0,0 +1,5 @@ +import { operationNames } from "./generated/graphql"; + +type QueryOperations = keyof typeof operationNames.Query; +type MutationOperations = keyof typeof operationNames.Mutation; +export type Operations = QueryOperations | MutationOperations; diff --git a/tsconfig.json b/tsconfig.json index 931591743..9ed120fc3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,13 @@ "types": ["cypress", "node", "vitest/importMeta"], "target": "es6" }, - "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"], - "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"], + "include": [ + "src/**/*.ts", + "src/**/*.tsx", + "src/**/*.js", + "src/**/*.jsx", + "cypress" + ], "ts-node": { // these options are overrides used only by ts-node "compilerOptions": { diff --git a/yarn.lock b/yarn.lock index b5e1a542f..f966d6f5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1668,6 +1668,15 @@ "@graphql-codegen/visitor-plugin-common" "^5.0.0" tslib "~2.6.0" +"@graphql-codegen/named-operations-object@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@graphql-codegen/named-operations-object/-/named-operations-object-3.1.0.tgz#25b79f725b17928501396179b8bfaff25b38aaa8" + integrity sha512-+k3dx91S7kVetRc2ZKBhQ22oIlcWPfdpyZMtUoLusWAdJ5G4Oyu324Sqq32yaUKHfrq5KSMIq7qv/wJUBmkEKQ== + dependencies: + "@graphql-codegen/plugin-helpers" "^3.0.0" + change-case-all "1.0.15" + tslib "~2.6.0" + "@graphql-codegen/plugin-helpers@^2.7.2": version "2.7.2" resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-2.7.2.tgz#6544f739d725441c826a8af6a49519f588ff9bed"