Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get meteor query result in resolver #80

Closed
wuzhuzhu opened this issue Aug 5, 2016 · 2 comments
Closed

Can't get meteor query result in resolver #80

wuzhuzhu opened this issue Aug 5, 2016 · 2 comments

Comments

@wuzhuzhu
Copy link

wuzhuzhu commented Aug 5, 2016

root schema and resolver:

const rootSchema = `
   type RootQuery {
    user: User    
   ...
    allFeedbacks: [Feedback]
   }

   schema {
    query: RootQuery
  }
`


RootQuery: {
...

    async allFeedbacks(root, args, context) {
      const allFeedbacks = DB.Feedback.find({patientId: {$exists: 1}}).fetch()
      return await allFeedbacks
    },
...
}

feedback.js

export const schema = `
  type Feedback {
    _id: String
    patient: User
    opinion: String
    reply: String
  }
`;

export const resolvers = {
  Feedback: {
    _id  : ({_id}) => _id,
    patient: async ({patientId}) => {
      return await Meteor.users.findOne({_id:patientId})
    },
    opinion: ({opinion}) => opinion,
    reply: ({reply}) => reply,
  }
};

query in graphiql:
{ allFeedbacks { patient { username } _id opinion reply } }

Got result:

{
"data": {
"allFeedbacks": [
{
"patient": null,
"_id": "nyNP9wh9D5qmZixbn",
"opinion": "tesst",
"reply": "testst"
},
{
"patient": null,
"_id": "WgSoCgTGhHeZasFGQ",
"opinion": "tesst",
"reply": "testst"
},

...
}

It's strange when i test , the resolver could console log PatientId, Meteor, Meteor.users, But can't get the fetched data. I guess the problem is on async, but where is the problem?

Had checked sample repos, followed their pattern but no luck.

@helfer
Copy link
Contributor

helfer commented Aug 5, 2016

@wuzhuzhu Are you getting any errors in that result? (at the bottom). I suspect that this may be a question that should be asked in the meteor-integration repository, so if you could re-open it there, that would be great.

@wuzhuzhu
Copy link
Author

wuzhuzhu commented Aug 5, 2016

there's are som errors...

Sure, I will move to this issue to meteor-integration repository and close this.

@wuzhuzhu wuzhuzhu closed this as completed Aug 5, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants