sarkistlt / mongoose-schema-to-graphql

Use Mongoose schema to generate graphQL type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot Generate GraphQL schemas with nested Mongoose Schemas

kevde opened this issue · comments

commented

Hi I was trying to create a mongoose schema and convert it into graphql. The structure is the following

export const BlogSchema = new Schema({
  tags: [{
    type: String,
  }],
  category: {
    type: String
  },
  cover: {
    photo: String,
    video: String,
  },

Then the it doesn't generate a graphql schema. Here is the error:

{
  "errors": [
    {
      "message": "Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"cover.photo\" does not.\n\nNames must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"cover.video\" does not.\n\nThe type of BlogType.cover must be Output Type but got: undefined.\n\nThe type of blogMutate.default must be Output Type but got: undefined."
    }
  ]
}

Initially, I have an assumption that the error was from
node_modules\graphql\utilities\assertValidName.js and it asserts that those fields are not valid. Do you of possible fix for it or workaround?

I have the exact issue.

is there a work around for this?

@SharePointPro hey, sorry for the late response. I'm currently busy with another project. PR welcome, project has all test cases and everything to make it easier, otherwise I can't give any certain timelines when I can get back to this project.