From 68ada9c2a644823b6058bfe3d51ee719be45e9a3 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Mon, 24 Jan 2022 19:44:05 -0500 Subject: [PATCH 1/8] fix: component spec creation with spec pattern --- .../src/actions/ProjectActions.ts | 25 ++++++++++++++++--- .../cypress/e2e/support/e2eProjectDirs.ts | 2 +- .../schemaTypes/objectTypes/gql-Mutation.ts | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index c45d3fd6254b..80d26c4f3ee1 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -318,9 +318,9 @@ export class ProjectActions { const parsed = path.parse(codeGenCandidate) const getFileExtension = () => { - if (codeGenType === 'e2e') { - const possibleExtensions = ['.spec', '.test', '-spec', '-test', '.cy', '_spec'] + const possibleExtensions = ['.cy', '.spec', '.test', '-spec', '-test', '_spec'] + if (codeGenType === 'e2e') { return ( possibleExtensions.find((ext) => { return codeGenCandidate.endsWith(ext + parsed.ext) @@ -328,7 +328,24 @@ export class ProjectActions { ) } - return '.cy' + const cfg = this.ctx.project.getConfig() + + if (!cfg?.component?.specPattern) { + return '.cy' + } + + const foundExt = possibleExtensions.find((ext) => { + const regexString = `^.*\.${ext}\..*$` + const regex = new RegExp(regexString) + + if (Array.isArray(cfg.component.specPattern)) { + return cfg.component.specPattern.some((val) => regex.test(val)) + } + + return new RegExp(regex).test(cfg.component.specPattern) + }) + + return foundExt } const getCodeGenPath = () => { @@ -361,6 +378,8 @@ export class ProjectActions { const [newSpec] = codeGenResults.files + // setSpec + return { status: 'valid', file: { absolute: newSpec.file, contents: newSpec.content }, diff --git a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts index 8b4c6c8de191..f432de17e445 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eProjectDirs.ts @@ -30,9 +30,9 @@ export const e2eProjectDirs = [ 'launchpad', 'max-listeners', 'migration', - 'multiple-task-registrations', 'multiple-config-files-with-json', 'multiple-support-files', + 'multiple-task-registrations', 'no-scaffolding', 'no-server', 'no-specs-found', diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 5512fa45c5c4..970b0545d250 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -193,7 +193,7 @@ export const mutation = mutationType({ codeGenCandidate: nonNull(stringArg()), type: nonNull(CodeGenTypeEnum), }, - resolve: async (_, args, ctx) => { + resolve: (_, args, ctx) => { return ctx.actions.project.codeGenSpec(args.codeGenCandidate, args.type) }, }) From 06531eed0a4d64a7aeec6940f8023f6a8ddd5082 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 25 Jan 2022 18:23:10 -0500 Subject: [PATCH 2/8] Update graphql type --- .../specs/generators/GeneratorCustomFile.vue | 93 +++++++++++++ .../src/specs/generators/GeneratorSuccess.vue | 17 ++- .../component/ComponentGeneratorStepOne.vue | 124 ++++++++++-------- .../empty/EmptyGeneratorCardStepOne.vue | 6 +- .../story/StoryGeneratorStepOne.vue | 7 +- .../src/actions/ProjectActions.ts | 81 ++++++++---- .../frontend-shared/src/locales/en-US.json | 3 +- packages/graphql/schemas/schema.graphql | 18 ++- packages/graphql/src/schemaTypes/index.ts | 1 + .../objectTypes/gql-GenerateSpecResponse.ts | 38 ++++++ .../objectTypes/gql-GeneratedSpecError.ts | 9 ++ .../schemaTypes/objectTypes/gql-Mutation.ts | 6 +- .../src/schemaTypes/objectTypes/index.ts | 2 + .../unions/gql-GeneratedSpecResult.ts | 19 +++ .../graphql/src/schemaTypes/unions/index.ts | 4 + 15 files changed, 336 insertions(+), 92 deletions(-) create mode 100644 packages/app/src/specs/generators/GeneratorCustomFile.vue create mode 100644 packages/graphql/src/schemaTypes/objectTypes/gql-GenerateSpecResponse.ts create mode 100644 packages/graphql/src/schemaTypes/objectTypes/gql-GeneratedSpecError.ts create mode 100644 packages/graphql/src/schemaTypes/unions/gql-GeneratedSpecResult.ts create mode 100644 packages/graphql/src/schemaTypes/unions/index.ts diff --git a/packages/app/src/specs/generators/GeneratorCustomFile.vue b/packages/app/src/specs/generators/GeneratorCustomFile.vue new file mode 100644 index 000000000000..9e8b96b35e4b --- /dev/null +++ b/packages/app/src/specs/generators/GeneratorCustomFile.vue @@ -0,0 +1,93 @@ + + + diff --git a/packages/app/src/specs/generators/GeneratorSuccess.vue b/packages/app/src/specs/generators/GeneratorSuccess.vue index 6c78a0343df0..57216d850c49 100644 --- a/packages/app/src/specs/generators/GeneratorSuccess.vue +++ b/packages/app/src/specs/generators/GeneratorSuccess.vue @@ -32,10 +32,11 @@ import ShikiHighlight from '@cy/components/ShikiHighlight.vue' import Collapsible from '@cy/components/Collapsible.vue' import { gql } from '@urql/core' -import type { GeneratorSuccessFragment } from '../../generated/graphql' +import type { GeneratorSuccessFileFragment } from '../../generated/graphql' +import { ref } from 'vue' gql` -fragment GeneratorSuccess on ScaffoldedFile { +fragment GeneratorSuccessFile on ScaffoldedFile { file { id fileName @@ -47,7 +48,17 @@ fragment GeneratorSuccess on ScaffoldedFile { } ` +gql` +fragment GeneratorSuccess on GenerateSpecResponse { + generatedSpecResult { + ... on ScaffoldedFile { + ...GeneratorSuccessFile + } + } +} +` + defineProps<{ - file: GeneratorSuccessFragment['file'] + file: GeneratorSuccessFileFragment['file'] }>() diff --git a/packages/app/src/specs/generators/component/ComponentGeneratorStepOne.vue b/packages/app/src/specs/generators/component/ComponentGeneratorStepOne.vue index 9e45116f3b15..9b42b792842c 100644 --- a/packages/app/src/specs/generators/component/ComponentGeneratorStepOne.vue +++ b/packages/app/src/specs/generators/component/ComponentGeneratorStepOne.vue @@ -1,57 +1,65 @@ @@ -62,11 +70,12 @@ import FileChooser from '../FileChooser.vue' import GeneratorSuccess from '../GeneratorSuccess.vue' import { computed, ref } from 'vue' import { gql, useQuery, useMutation } from '@urql/vue' -import { ComponentGeneratorStepOneDocument, ComponentGeneratorStepOne_GenerateSpecDocument, GeneratorSuccessFragment } from '../../../generated/graphql' +import { ComponentGeneratorStepOneDocument, ComponentGeneratorStepOne_GenerateSpecDocument, GeneratorSuccessFileFragment } from '../../../generated/graphql' import StandardModalFooter from '@cy/components/StandardModalFooter.vue' import Button from '@cy/components/Button.vue' import PlusButtonIcon from '~icons/cy/add-large_x16.svg' import TestResultsIcon from '~icons/cy/test-results_x24.svg' +import GeneratorCustomFile from '../GeneratorCustomFile.vue' const props = defineProps<{ title: string, @@ -115,6 +124,7 @@ query ComponentGeneratorStepOne($glob: String!) { gql` mutation ComponentGeneratorStepOne_generateSpec($codeGenCandidate: String!, $type: CodeGenType!) { generateSpecFromSource(codeGenCandidate: $codeGenCandidate, type: $type) { + ...GeneratorCustomFile ...GeneratorSuccess } }` @@ -138,7 +148,9 @@ const allFiles = computed((): any => { return [] }) -const result = ref(null) +const result = ref(null) +const generatedSpecErrorFileName = ref() +const generateSpecFromSource = ref() whenever(result, () => { title.value = t('createSpec.successPage.header') @@ -150,7 +162,9 @@ const makeSpec = async (file) => { type: 'component', }) - result.value = data?.generateSpecFromSource ?? null + generateSpecFromSource.value = data?.generateSpecFromSource + result.value = data?.generateSpecFromSource?.generatedSpecResult?.__typename === 'ScaffoldedFile' ? data?.generateSpecFromSource?.generatedSpecResult : null + generatedSpecErrorFileName.value = data?.generateSpecFromSource?.generatedSpecResult?.__typename === 'GeneratedSpecError' ? data?.generateSpecFromSource?.generatedSpecResult.fileName : null } diff --git a/packages/app/src/specs/generators/empty/EmptyGeneratorCardStepOne.vue b/packages/app/src/specs/generators/empty/EmptyGeneratorCardStepOne.vue index 4aab655e2f55..68cc67a47d1c 100644 --- a/packages/app/src/specs/generators/empty/EmptyGeneratorCardStepOne.vue +++ b/packages/app/src/specs/generators/empty/EmptyGeneratorCardStepOne.vue @@ -98,7 +98,7 @@ import Button from '@packages/frontend-shared/src/components/Button.vue' import { useVModels, whenever } from '@vueuse/core' import { gql, useMutation } from '@urql/vue' import SpecPatterns from '../../../components/SpecPatterns.vue' -import { EmptyGeneratorCardStepOneFragment, EmptyGeneratorCardStepOne_MatchSpecFileDocument, EmptyGeneratorCardStepOne_GenerateSpecDocument, GeneratorSuccessFragment } from '../../../generated/graphql' +import { EmptyGeneratorCardStepOneFragment, EmptyGeneratorCardStepOne_MatchSpecFileDocument, EmptyGeneratorCardStepOne_GenerateSpecDocument, GeneratorSuccessFileFragment } from '../../../generated/graphql' import StandardModalFooter from '@packages/frontend-shared/src/components/StandardModalFooter.vue' import GeneratorSuccess from '../GeneratorSuccess.vue' import TestResultsIcon from '~icons/cy/test-results_x24.svg' @@ -151,7 +151,7 @@ const writeFile = useMutation(EmptyGeneratorCardStepOne_GenerateSpecDocument) const isValidSpecFile = ref(true) const hasError = computed(() => !isValidSpecFile.value && !!specFile.value) -const result = ref(null) +const result = ref(null) whenever(result, () => { title.value = t('createSpec.successPage.header') @@ -160,7 +160,7 @@ whenever(result, () => { const createSpec = async () => { const { data } = await writeFile.executeMutation({ codeGenCandidate: specFile.value, type: 'e2e' }) - result.value = data?.generateSpecFromSource ?? null + result.value = data?.generateSpecFromSource?.generatedSpecResult?.__typename === 'ScaffoldedFile' ? data?.generateSpecFromSource?.generatedSpecResult : null } watch(specFile, async (value) => { diff --git a/packages/app/src/specs/generators/story/StoryGeneratorStepOne.vue b/packages/app/src/specs/generators/story/StoryGeneratorStepOne.vue index 92db8913e169..76d38c92223b 100644 --- a/packages/app/src/specs/generators/story/StoryGeneratorStepOne.vue +++ b/packages/app/src/specs/generators/story/StoryGeneratorStepOne.vue @@ -62,7 +62,7 @@ import FileChooser from '../FileChooser.vue' import GeneratorSuccess from '../GeneratorSuccess.vue' import { computed, ref } from 'vue' import { gql, useQuery, useMutation } from '@urql/vue' -import { GeneratorSuccessFragment, StoryGeneratorStepOneDocument, StoryGeneratorStepOne_GenerateSpecDocument } from '../../../generated/graphql' +import { GeneratorSuccessFileFragment, StoryGeneratorStepOneDocument, StoryGeneratorStepOne_GenerateSpecDocument } from '../../../generated/graphql' import StandardModalFooter from '@cy/components/StandardModalFooter.vue' import Button from '@cy/components/Button.vue' import PlusButtonIcon from '~icons/cy/add-large_x16.svg' @@ -115,6 +115,7 @@ query StoryGeneratorStepOne($glob: String!) { gql` mutation StoryGeneratorStepOne_generateSpec($codeGenCandidate: String!, $type: CodeGenType!) { generateSpecFromSource(codeGenCandidate: $codeGenCandidate, type: $type) { + ...GeneratorCustomFile ...GeneratorSuccess } }` @@ -138,7 +139,7 @@ const allFiles = computed(() => { return [] }) as any -const result = ref(null) +const result = ref(null) whenever(result, () => { title.value = t('createSpec.successPage.header') @@ -150,7 +151,7 @@ const makeSpec = async (file) => { type: 'story', }) - result.value = data?.generateSpecFromSource ?? null + result.value = data?.generateSpecFromSource?.generatedSpecResult?.__typename === 'ScaffoldedFile' ? data?.generateSpecFromSource?.generatedSpecResult : null } diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 80d26c4f3ee1..37f06ba8ad04 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -1,4 +1,4 @@ -import type { CodeGenType, MutationSetProjectPreferencesArgs, NexusGenObjects, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' +import type { CodeGenType, MutationSetProjectPreferencesArgs, NexusGenObjects, NexusGenUnions, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' import type { InitializeProjectOptions, FoundBrowser, FoundSpec, LaunchOpts, OpenProjectLaunchOptions, Preferences, TestingType, ReceivedCypressOptions, AddProject } from '@packages/types' import execa from 'execa' import path from 'path' @@ -308,7 +308,7 @@ export class ProjectActions { this.api.insertProjectPreferencesToCache(this.ctx.lifecycleManager.projectTitle, args) } - async codeGenSpec (codeGenCandidate: string, codeGenType: CodeGenType): Promise { + async codeGenSpec (codeGenCandidate: string, codeGenType: CodeGenType): Promise { const project = this.ctx.currentProject if (!project) { @@ -316,10 +316,10 @@ export class ProjectActions { } const parsed = path.parse(codeGenCandidate) + const defaultCText = '.cy' + const possibleExtensions = ['.cy', '.spec', '.test', '-spec', '-test', '_spec'] const getFileExtension = () => { - const possibleExtensions = ['.cy', '.spec', '.test', '-spec', '-test', '_spec'] - if (codeGenType === 'e2e') { return ( possibleExtensions.find((ext) => { @@ -328,24 +328,7 @@ export class ProjectActions { ) } - const cfg = this.ctx.project.getConfig() - - if (!cfg?.component?.specPattern) { - return '.cy' - } - - const foundExt = possibleExtensions.find((ext) => { - const regexString = `^.*\.${ext}\..*$` - const regex = new RegExp(regexString) - - if (Array.isArray(cfg.component.specPattern)) { - return cfg.component.specPattern.some((val) => regex.test(val)) - } - - return new RegExp(regex).test(cfg.component.specPattern) - }) - - return foundExt + return defaultCText } const getCodeGenPath = () => { @@ -366,7 +349,37 @@ export class ProjectActions { specFileExtension, }) - const codeGenOptions = await newSpecCodeGenOptions.getCodeGenOptions() + let codeGenOptions = await newSpecCodeGenOptions.getCodeGenOptions() + + if (codeGenType === 'component') { + const filePathAbsolute = path.join(path.parse(codeGenPath).dir, codeGenOptions.fileName) + const filePathRelative = path.relative(this.ctx.currentProject || '', filePathAbsolute) + + let foundExt + + for await (const ext of possibleExtensions) { + const file = filePathRelative.replace(defaultCText, ext) + + const matchesSpecPattern = await this.ctx.project.matchesSpecPattern(file) + + if (matchesSpecPattern) { + foundExt = ext + break + } + } + + if (!foundExt) { + return { + fileName: filePathRelative, + } + } + + codeGenOptions = { + ...codeGenOptions, + fileName: codeGenOptions.fileName.replace(defaultCText, foundExt), + } + } + const codeGenResults = await codeGenerator( { templateDir: templates[codeGenType], target: path.parse(codeGenPath).dir }, codeGenOptions, @@ -378,7 +391,27 @@ export class ProjectActions { const [newSpec] = codeGenResults.files - // setSpec + const cfg = this.ctx.project.getConfig() + + if (cfg) { + const toArray = (x: string | string[] | undefined) => Array.isArray(x) ? x : x ? [x] : undefined + + const testingType = codeGenType === 'component' ? 'component' : 'e2e' + + const specPattern = toArray(cfg[testingType]?.specPattern) + const ignoreSpecPattern = toArray(cfg[testingType]?.ignoreSpecPattern) ?? [] + const additionalIgnore = toArray(codeGenType === 'component' ? cfg?.e2e?.specPattern : undefined) ?? [] + + if (this.ctx.currentProject && specPattern) { + const specs = await this.ctx.project.findSpecs(this.ctx.currentProject, testingType, specPattern, ignoreSpecPattern, additionalIgnore) + + this.ctx.project.setSpecs(specs) + + if (testingType === 'component') { + this.api.getDevServer().updateSpecs(specs) + } + } + } return { status: 'valid', diff --git a/packages/frontend-shared/src/locales/en-US.json b/packages/frontend-shared/src/locales/en-US.json index 3068f975337e..d5f88b94e178 100644 --- a/packages/frontend-shared/src/locales/en-US.json +++ b/packages/frontend-shared/src/locales/en-US.json @@ -110,7 +110,8 @@ "importFromComponent": { "header": "Create from component", "description": "We'll generate an empty spec file which can be used to import and test any component in this project.", - "chooseAComponentHeader": "Choose a component" + "chooseAComponentHeader": "Choose a component", + "invalidComponentWarning": "We couldn't generate a valid filename matching your custom " } } }, diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index 9a5e57a28f33..ce02ed44157f 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -494,6 +494,22 @@ enum FrontendFrameworkEnum { vuecli } +"""Error from generated spec""" +type GenerateSpecResponse { + """The currently opened project""" + currentProject: CurrentProject + + """The file that have just been scaffolded or the fileName that errored""" + generatedSpecResult: GeneratedSpecResult +} + +"""Error from generated spec""" +type GeneratedSpecError { + fileName: String! +} + +union GeneratedSpecResult = GeneratedSpecError | ScaffoldedFile + """Git information about a spec file""" type GitInfo { """Last person to change the file in git""" @@ -607,7 +623,7 @@ type Mutation { devRelaunch(action: DevRelaunchAction!): Boolean """Generate spec from source""" - generateSpecFromSource(codeGenCandidate: String!, type: CodeGenType!): ScaffoldedFile + generateSpecFromSource(codeGenCandidate: String!, type: CodeGenType!): GenerateSpecResponse """Hides the launchpad windows""" hideBrowserWindow: Boolean! diff --git a/packages/graphql/src/schemaTypes/index.ts b/packages/graphql/src/schemaTypes/index.ts index 8271aa0416d0..9e2665df8ba6 100644 --- a/packages/graphql/src/schemaTypes/index.ts +++ b/packages/graphql/src/schemaTypes/index.ts @@ -6,3 +6,4 @@ export * from './inputTypes/' export * from './interfaceTypes/' export * from './objectTypes/' export * from './scalarTypes/' +export * from './unions/' diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-GenerateSpecResponse.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-GenerateSpecResponse.ts new file mode 100644 index 000000000000..6f9d7e2add53 --- /dev/null +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-GenerateSpecResponse.ts @@ -0,0 +1,38 @@ +import { objectType } from 'nexus' +import { GeneratedSpecResult } from '../unions' +import { CurrentProject } from './gql-CurrentProject' +import type { FilePartsShape } from './gql-FileParts' + +export interface ScaffoldedFileSource { + status: 'changes' | 'valid' | 'skipped' | 'error' + description: string + file: FilePartsShape +} + +export const GenerateSpecResponse = objectType({ + name: 'GenerateSpecResponse', + description: 'Error from generated spec', + definition (t) { + t.field('currentProject', { + type: CurrentProject, + description: 'The currently opened project', + resolve: (root, args, ctx) => { + if (ctx.coreData.currentProject) { + return ctx.lifecycleManager + } + + return null + }, + }) + + t.field('generatedSpecResult', { + type: GeneratedSpecResult, + description: 'The file that have just been scaffolded or the fileName that errored', + resolve: (root, args, ctx) => root, + }) + }, + sourceType: { + module: __filename, + export: 'ScaffoldedFileSource', + }, +}) diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-GeneratedSpecError.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-GeneratedSpecError.ts new file mode 100644 index 000000000000..9887c3165847 --- /dev/null +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-GeneratedSpecError.ts @@ -0,0 +1,9 @@ +import { objectType } from 'nexus' + +export const GeneratedSpecError = objectType({ + name: 'GeneratedSpecError', + description: 'Error from generated spec', + definition (t) { + t.nonNull.string('fileName') + }, +}) diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 970b0545d250..4cdc5256d1a4 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -5,7 +5,9 @@ import { TestingTypeEnum } from '../enumTypes/gql-WizardEnums' import { FileDetailsInput } from '../inputTypes/gql-FileDetailsInput' import { WizardUpdateInput } from '../inputTypes/gql-WizardUpdateInput' import { CurrentProject } from './gql-CurrentProject' -import { Query, ScaffoldedFile } from '.' +import { GenerateSpecResponse } from './gql-GenerateSpecResponse' +import { Query } from './gql-Query' +import { ScaffoldedFile } from './gql-ScaffoldedFile' export const mutation = mutationType({ definition (t) { @@ -187,7 +189,7 @@ export const mutation = mutationType({ }) t.field('generateSpecFromSource', { - type: ScaffoldedFile, + type: GenerateSpecResponse, description: 'Generate spec from source', args: { codeGenCandidate: nonNull(stringArg()), diff --git a/packages/graphql/src/schemaTypes/objectTypes/index.ts b/packages/graphql/src/schemaTypes/objectTypes/index.ts index bf78e5383888..5d826e90fe02 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/index.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/index.ts @@ -8,6 +8,8 @@ export * from './gql-CurrentProject' export * from './gql-DevState' export * from './gql-Editor' export * from './gql-FileParts' +export * from './gql-GenerateSpecResponse' +export * from './gql-GeneratedSpecError' export * from './gql-GitInfo' export * from './gql-GlobalProject' export * from './gql-LocalSettings' diff --git a/packages/graphql/src/schemaTypes/unions/gql-GeneratedSpecResult.ts b/packages/graphql/src/schemaTypes/unions/gql-GeneratedSpecResult.ts new file mode 100644 index 000000000000..5a38a52a40f6 --- /dev/null +++ b/packages/graphql/src/schemaTypes/unions/gql-GeneratedSpecResult.ts @@ -0,0 +1,19 @@ +import { unionType } from 'nexus' + +export const GeneratedSpecResult = unionType({ + name: 'GeneratedSpecResult', + definition (t) { + t.members( + 'ScaffoldedFile', + 'GeneratedSpecError', + ) + }, + resolveType: (obj) => { + // @ts-expect-error + if (obj.fileName) { + return 'GeneratedSpecError' + } + + return 'ScaffoldedFile' + }, +}) diff --git a/packages/graphql/src/schemaTypes/unions/index.ts b/packages/graphql/src/schemaTypes/unions/index.ts new file mode 100644 index 000000000000..66f93711cb1b --- /dev/null +++ b/packages/graphql/src/schemaTypes/unions/index.ts @@ -0,0 +1,4 @@ +/* eslint-disable padding-line-between-statements */ +// created by autobarrel, do not modify directly + +export * from './gql-GeneratedSpecResult' From be2d3eb684e77469bdca577371846fdcd257ad20 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Tue, 25 Jan 2022 20:47:32 -0500 Subject: [PATCH 3/8] Create spec from app --- .../specs/generators/GeneratorCustomFile.vue | 64 +++++++++++++++---- .../src/actions/ProjectActions.ts | 10 ++- .../data-context/src/util/urqlCacheKeys.ts | 2 + .../objectTypes/gql-GenerateSpecResponse.ts | 4 +- 4 files changed, 62 insertions(+), 18 deletions(-) diff --git a/packages/app/src/specs/generators/GeneratorCustomFile.vue b/packages/app/src/specs/generators/GeneratorCustomFile.vue index 9e8b96b35e4b..a9a837171b41 100644 --- a/packages/app/src/specs/generators/GeneratorCustomFile.vue +++ b/packages/app/src/specs/generators/GeneratorCustomFile.vue @@ -1,9 +1,9 @@ -