GraphQL is resolving my title and content properties as null, though the data is definitely being retrieved from the server - the console log in the confirms it. Only the _id property is returned from graphql, this is what I get back from the query json { listings: [ { _id: '56e6c94f1cf94a7c0a4e22ba', title: null, content: null } ] } As far as I can tell everything is set up correctly, I also tried giving title and content a GraphQLIDType to rule out the differences it types.
I have a graphql query:
query(` query findListings { listings(offset: 1) { _id, title, content } } `).then((json) => { console.log('json', json.data) }) my root query type:
const QueryType = new GraphQLObjectType({ name: 'Query', fields: { listings: { name: 'listings', type: new GraphQLList(ListingType), args: { limit: { type: GraphQLInt }, offset: { type: GraphQLInt } }, resolve(source, args, info) { const { fieldASTs } = info const projection = getProjection(fieldASTs[0]) return ListingModel.find({}, projection).then(listing => { console.log(listing) return listing }) } } } }) and my "listing type":
const ListingType = new GraphQLObjectType({ name: 'Listing', fields: { _id: { type: GraphQLID }, title: { type: GraphQLString }, content: { type: GraphQLString } } })
0 comments:
Post a Comment