# GraphQL Query Issue Array of Objects

**URL:** <https://community.apollographql.com/t/graphql-query-issue-array-of-objects/5848>\
**Category:** General\
**Created:** [March 2, 2023, 12:05am UTC](https://community.apollographql.com/t/graphql-query-issue-array-of-objects/5848 "2023-03-02T00:05:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lindylex](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lindylex/32/3775_2.png) [@lindylex](https://community.apollographql.com/u/lindylex)\
**Post date:** [March 2, 2023, 12:05am UTC](https://community.apollographql.com/t/graphql-query-issue-array-of-objects/5848/1 "2023-03-02T00:05:31Z")

</div>

My GraphQL sandbox localhost at port 4000

Problem : I am querying for data and not sure how to construct the typeDefs for Graphql and mongoose description of the database. It provides me an array/list of objects and that is what I do not understand how to construct.

Operation

```auto
query test {
  experiences {
    experience
  }
}

```

Error :

```auto
{
  "data": {
    "experiences": [
      {
        "experience": null
      }
    ]
  },
  "errors": [
    {
      "message": "String cannot represent value: { pastProjects: [Array], AAA: [Array], audioServer: [Array], BBB: [Array], assetMap: [Array], CCC: [Array], chicmedia: [Array], chicmedia2: [Array], songspub: [Array], indelible: [Array], DDD: [Array], foundations: [Array], vistarr: [Array], ctny: [Array], sportCut: [Array], EEE: [Array] }",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "experiences",
        0,
        "experience"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "GraphQLError: String cannot represent value: { pastProjects: [Array], AAA: [Array], audioServer: [Array], BBB: [Array], assetMap: [Array], CCC: [Array], chicmedia: [Array], chicmedia2: [Array], songspub: [Array], indelible: [Array], DDD: [Array], foundations: [Array], vistarr: [Array], ctny: [Array], sportCut: [Array], EEE: [Array] }",
          
      
Books.js

const pastProjectsSchema = new mongoose.Schema({
    experience: {
        pastProjects:{
            1:[]
        }
    }
        

})

export const Experience = mongoose.model( "Experience", pastProjectsSchema , "experience");

```

typeDefs.js

```auto
import gql from 'graphql-tag';

export const typeDefs = gql`
    type Query {
        experiences:[Experience]
    }

    type Experience{
        experience: String
    }
`;

```

resolvers.js

```auto
import { Experience} from './models/Book.js'

export const resolvers = {
    Query: {
        experiences: async() => await Experience.find({})
    }
};

```

Short Sample MongoosedDB Data

```auto
      {
        "experience": {
          "pastProjects": [
            {
              "1": [
                {
                  "title": "One"
                }
              ]
            },
            {
              "2": [
                {
                  "title:": "TWO"
                }
              ]
            }
     	]
      }
    }
          

```

---

<div class="post-metadata">

**Author:** ![lindylex](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lindylex/32/3775_2.png) [@lindylex](https://community.apollographql.com/u/lindylex)\
**Post date:** [March 3, 2023, 5:13pm UTC](https://community.apollographql.com/t/graphql-query-issue-array-of-objects/5848/2 "2023-03-03T17:13:58Z")

</div>

]SOLVED SOLUTION [

I took some time to restructure the JSON.  
It looks like this in MongoDB.

```auto
              {
    	"pastprojects": [{
    			"title": "One Title",
    			"main": "- Blah Line 1<br>- Blah Line 2",
    			"sub": "Sub One Description"
    
    		},
    		{
    			"title": "Two Title",
    			"main": "- Blah Line 1<br>- Blah Line 2",
    			"sub": "Sub Two Description"
    
    		}
    
    	]
    }

```

This is my mongoose.model in file Book.js:

```auto
        import mongoose from "mongoose";
    const pastProjectsSchema = new mongoose.Schema({
            pastprojects:[
                    {   
                        title: String,
                        main: String,
                        sub: String
                    }
                ]
                
        })
        
        export const Experience = mongoose.model( "Experience", pastProjectsSchema , "pastprojects");

```

```
This is my GraphQl typeDefs.js:

```

```auto
            import gql from 'graphql-tag';   
        export const typeDefs = gql`
            type Query {
                experiences: [Experience]
            }
            type Experience {
                pastprojects: [ProjectDetail]
              }
            
              type ProjectDetail {
                title: String
                main: String
                sub: String
              }
               
        `;

```

This is my resolver.js :

```auto
        import { Experience} from './models/Book.js'
    
    export const resolvers = {
        Query: {
            experiences: async() => await Experience.find({}),
        }
    };

```

Hope this help someone.

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:49pm UTC](https://community.apollographql.com/t/graphql-query-issue-array-of-objects/5848/3 "2025-02-06T20:49:24Z")

</div>


