简体   繁体   中英

My graphQl query find returns null response on GraphQL Playground but on console there is array of find data

query GetJourneys {
 getJourneyById(userId: "61dcc7de6d06a5db38d7b6e0"){
  id
  city
  trip
  tripName
  duration
  userId
}
}

So when I run this query and my resolver has const journey = await Journey.find({ userId: userId }); it returns null in all fields

instead when I do it as findOne there is correct response but only 1 object comes like this

  {
    _id: 61de5fb2130167512ed537dc,
    city: 'Indonesia Convention Exhibition (ICE) BSD City',
    trip: 0,
    tripName: 'Indonesia Trip',
    duration: 1,
    url: 'http://www.ice-indonesia.com/',
    userId: '61dcc7de6d06a5db38d7b6e0',
    cityId: 'ChIJBSMVX1P7aS4RePSYsNhuQDQ',
    __v: 0
  }
]

Only on GraphQL playground data returns as null what can be the reason?

Your Journey.find returns an array. That's why its not working. findOne returns an object, that's why its working.

In your GraphQL Query, you need to set your return into array, just put square bracket around what you have now, it will work. Eg you got example type:Journey in your type Query, just change it to:[Journey] and it will work. The square bracket means an array of Journey.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM