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
Error :
Books.js
typeDefs.js
resolvers.js
Short Sample MongoosedDB Data
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
query test {
experiences {
experience
}
}
Error :
{
"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
import gql from 'graphql-tag';
export const typeDefs = gql`
type Query {
experiences:[Experience]
}
type Experience{
experience: String
}
`;
resolvers.js
import { Experience} from './models/Book.js'
export const resolvers = {
Query: {
experiences: async() => await Experience.find({})
}
};
Short Sample MongoosedDB Data
{
"experience": {
"pastProjects": [
{
"1": [
{
"title": "One"
}
]
},
{
"2": [
{
"title:": "TWO"
}
]
}
]
}
}