1

I created a GraphQL server in combination with Express + MongoDB. I started with the following data model:

const AuthorSchema = new Schema({
  name: { type: String, required: true },
  age: { type: Number, required: true },
});

Queries + Mutations are working, but I decided to add more fields to the data model:

const AuthorSchema = new Schema({
  name: { type: String, required: true },
  age: { type: Number, required: true },
  bio: { type: String, required: true },
  picture: { type: String, required: true }
});

I can add a new author through a mutation with the new fields, but for some reason, queries will not return the new fields.

{
  "errors": [
    {
      "message": "Cannot query field \"bio\" on type \"Author\".",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    }
  ]
}```
Tyler Knapp
  • 93
  • 1
  • 9

1 Answers1

0

Your GraphQL types are not the same as your Mongoose schemas. If you add a field to AuthorSchema schema and want to also expose this as a field on your Author type, then you need to explicitly define the field in your GraphQL schema.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183