sarkistlt / mongoose-schema-to-graphql

Use Mongoose schema to generate graphQL type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors with the created types

truca opened this issue · comments

TL;DR:
The import didn't worked on typescript, so after many approaches, i changed the export from the package to:

export default function createType(config: ConfigurationObject): any;

But now i got this error:

suscriptorType.obj field type must be Output Type but got: undefined.

My code:

const suscriptorSchema = new mongoose.Schema({ mail: String })
const suscriptor = mongoose.model('Suscriptor', suscriptorSchema);
const suscriptorGQL = createType({
    name: 'suscriptorType',
    description: '',
    class: 'GraphQLObjectType' as ClassFieldType,
    schema: suscriptorSchema,
    extend: {}
})

I was using version 2.5.7 without problems, but when i tried to update to version 2.6.8 i couldn't make the import work, and now that i solved that this problem occur. I would love some help to integrate the new version

Solved the issue. The version 2.5.7 supported object attributes, but in the version 2.6.8 every object attribute should be another type.

2.5.7:

const animal = mongoose.Schema({
    parts: {
        tails: Number
        legs: Number
    }
})

2.6.8:

const partsSchema = mongoose.Schema({
    tails: Number
    legs: Number
})

const animalSchema = mongoose.Schema({
    parts: partsSchema
})