How to define GraphQLObjectType for a nested object or list of objects in the same parent object How to define GraphQLObjectType for a nested object or list of objects in the same parent object mongoose mongoose

How to define GraphQLObjectType for a nested object or list of objects in the same parent object


I believe what you are trying to do here is have your documents field be a list of documents. In order to do this, you need to create a "document" GraphQLObjectType to pass into new GraphQLList() in your documents field. Like so:

const DocumentType = new GraphQLObjectType({  name: 'DocumentType',  fields: {    doc_name: {      type: GraphQLString    },    doc_url: {      type: GraphQLString    },    status: {      type: GraphQLBoolean  }});

Then once you have that created, either in the same file (or in a different file and imported necessarily) with the right dependencies, you plug it into the code you posted above like so:

fields() {        return {            name: {                type: GraphQLString,                description: 'Name of the person'            },            age: {                type: GraphQLString,                description: 'Age'            },            documents: {                type: new GraphQLList(DocumentType),                description: 'All documents for the person'            }       }}  

I hope this helps.