graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.39k stars 274 forks source link

use Typescript enum from module, in Nexus Enum as input #497

Open krtooch opened 4 years ago

krtooch commented 4 years ago

Hello,

My issue is very close to 335.

I d'like to use a Interface (from a node_module) to define a Nexus Enum, and use it as inputType for a resolver, to a fonction who accept DocumentCategory (same as 355 issue but with a interface from lib)

import {DocumentCategory} from 'myModule/document'

// // enum DocumentCategory { // CV:'Curriculum', // IBAN: 'bank' // } //

const DocumentEnum = enumType({ name: "DocumentCategory", members: DocumentCategory });

export const schema = makeSchema({ types: [DocumentEnum], outputs: { schema: path.join(dirname, "my-schema.graphql"), typegen: path.join(dirname, "../../../src/generated/index.ts"), }, shouldGenerateArtifacts: true, typegenAutoConfig: { contextType: 'ctx.Context', debug :true, sources: [ { alias: "ctx", source: path.join(__dirname, "../../../src/Graphql/Frame/Context/index.ts"), }, { alias: "doc", source:'myModule/document', typeMatch: name => new RegExp((?:interface|type|class|enum)\\s+(${name}s?)\\W, "g") } ] } });


With the debug option true, i can't see it search in my nodemodule, i tried tu put relative and absolute path, but nothing seem to work.

Note that my module only have compiled files, and not TS file.

Should we give in source field directly the DocumentCategory imported bellow? thank you
Sytten commented 4 years ago

Can you add the definition of the enum, the converter might not see it as an enum.

krtooch commented 4 years ago

// myModule/document.ts

export enum DocumentCategory {

        AVATAR = 'avatar',

    BONUS = 'bonus',

    CERTIFICATE = 'certificate',

    CURRICULUM_VITAE = 'curriculumVitae',

    IBAN = 'IBAN',
}
Sytten commented 3 years ago

Sorry this was lost in my notifications, I feel this is weird because I never see TS files in node_modules. Can you check if the import was added to the generated/index.ts

bentron2000 commented 3 years ago

Just a note here. Is typegenAutoConfig meant to appear in the type declarations for SchemaConfig? I get an error that this is not defined.