diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7132a16..05e7aa7 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,11 @@ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.3/containers/typescript-node/.devcontainer/base.Dockerfile # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster -ARG VARIANT="16-bullseye" -FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} +# Every allowed variants: https://mcr.microsoft.com/v2/vscode/devcontainers/javascript-node/tags/list +# Doc of each tags: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/typescript-node/history +# Node v16.15.1 +ARG VARIANT="0.204.1-16-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:${VARIANT} # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a01eff5..fb45ed7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,6 @@ jobs: - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' - cache: 'yarn' - name: Check - Yarn dedupe run: yarn dedupe -c diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cdb6461..3950743 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,6 @@ jobs: - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' - cache: 'yarn' - name: Build run: yarn build diff --git a/.nvmrc b/.nvmrc index 6f7f377..dac255d 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v16 +v16.15.1 diff --git a/package.json b/package.json index a14e6d1..a751b8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-gql-plugin", - "version": "1.4.0", + "version": "1.4.1", "packageManager": "yarn@3.2.1", "license": "MIT", "main": "./dist/index.js", diff --git a/src/cached/cached-literal-parser.ts b/src/cached/cached-literal-parser.ts index 3ff3d83..d33437e 100644 --- a/src/cached/cached-literal-parser.ts +++ b/src/cached/cached-literal-parser.ts @@ -3,7 +3,11 @@ import { ErrorCatcher } from '../create-error-catcher'; import { generateTypeFromLiteral } from '../generators/generate-type-from-literal'; import { DocumentInfos } from '../generators/generate-bottom-content'; import { createCacheSystem } from '../utils/cache-system'; -import { CachedSchemaLoader, defaultProjectName } from './cached-schema-loader'; +import { + CachedSchemaLoader, + defaultProjectName, + getProjectNameIfNotDefault, +} from './cached-schema-loader'; type CreateCachedLiteralParserOptions = { cachedSchemaLoader: CachedSchemaLoader; @@ -44,7 +48,7 @@ export const createCachedLiteralParser = ({ throw new Error(`Project not defined for name "${projectName}"`); } - return project; + return { ...project, projectName }; }; const parser = createCacheSystem< @@ -60,6 +64,7 @@ export const createCachedLiteralParser = ({ documentInfos: await generateTypeFromLiteral( literal, project.schemaDocument, + getProjectNameIfNotDefault(project.projectName), project.extension.codegenConfig ), staticGlobals: project.staticGlobals, diff --git a/src/cached/cached-schema-loader.ts b/src/cached/cached-schema-loader.ts index 15c55ca..23b3bd8 100644 --- a/src/cached/cached-schema-loader.ts +++ b/src/cached/cached-schema-loader.ts @@ -29,6 +29,9 @@ export type CachedSchemaLoader = ReturnType; export const defaultProjectName = 'default'; +export const getProjectNameIfNotDefault = (projectName: string) => + projectName === defaultProjectName ? undefined : projectName; + export const createCachedSchemaLoader = ({ cachedGraphQLConfigLoader, errorCatcher, @@ -61,7 +64,7 @@ export const createCachedSchemaLoader = ({ schemaDocument, staticGlobals: await generateTypeFromSchema( schemaDocument, - projectName === defaultProjectName ? undefined : projectName, + getProjectNameIfNotDefault(projectName), extension.codegenConfig ), extension, diff --git a/src/generators/generate-type-from-literal.ts b/src/generators/generate-type-from-literal.ts index 3305290..4537a65 100644 --- a/src/generators/generate-type-from-literal.ts +++ b/src/generators/generate-type-from-literal.ts @@ -9,6 +9,7 @@ const plugins = [typescriptOperationsPlugin]; export const generateTypeFromLiteral = async ( literal: string, schema: DocumentNode, + projectName?: string, codegenConfig: typescriptOperationsPlugin.TypeScriptDocumentsPluginConfig = {} ): Promise => { const document = parse(literal); @@ -22,6 +23,7 @@ export const generateTypeFromLiteral = async ( ); const config: typescriptOperationsPlugin.TypeScriptDocumentsPluginConfig = { + typesPrefix: projectName, ...codegenConfig, }; diff --git a/src/source-update/create-source-updater.test.ts b/src/source-update/create-source-updater.test.ts index 6f83cb9..c5aad26 100644 --- a/src/source-update/create-source-updater.test.ts +++ b/src/source-update/create-source-updater.test.ts @@ -302,6 +302,7 @@ describe('Create source updater', () => { user(id: $id) { id name + provider } users { id @@ -401,7 +402,12 @@ describe('Create source updater', () => { export interface DocumentMap { [${query1.slice(4, -1)}]: TypedDocumentNode<{ __typename?: "Query"; - user: { __typename?: "User"; id: string; name: string }; + user: { + __typename?: "User"; + id: string; + name: string; + provider?: CatalogProvider | null; + }; users: Array<{ __typename?: "User"; id: string; email: string }>; }, Exact<{ id: Scalars["ID"]; @@ -440,6 +446,7 @@ describe('Create source updater', () => { email: Scalars["String"]; name: Scalars["String"]; picture?: Maybe; + provider?: Maybe; }; export interface CatalogQuery { @@ -452,6 +459,8 @@ describe('Create source updater', () => { id: Scalars["ID"]; }; + export type CatalogProvider = "GOOGLE" | "FACEBOOK"; + /** All built-in and custom scalars, mapped to their actual values */ export interface Scalars { ID: string; diff --git a/src/test-files/multi-project/catalog-schema.graphql b/src/test-files/multi-project/catalog-schema.graphql index 043451e..90e5c3f 100644 --- a/src/test-files/multi-project/catalog-schema.graphql +++ b/src/test-files/multi-project/catalog-schema.graphql @@ -4,9 +4,15 @@ type User { email: String! name: String! picture: String + provider: Provider } type Query { users: [User!]! user(id: ID!): User! } + +enum Provider { + GOOGLE + FACEBOOK +}