sarkistlt / mongoose-schema-to-graphql

Use Mongoose schema to generate graphQL type.
230 stars 28 forks source link

Cannot Generate GraphQL schemas with nested Mongoose Schemas #25

Open kevde opened 6 years ago

kevde commented 6 years ago

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?

SharePointPro commented 5 years ago

I have the exact issue.

SharePointPro commented 5 years ago

is there a work around for this?

sarkistlt commented 5 years ago

@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.