Query all users from meteor

Hi All, I tries to query all the users from meteor using apollo.

const GET_USERS = gql`
  query {
    users {
      _id,
      username,
      emails,
    }
  }
`;

const UserListWithData = graphql(GET_USERS, {
  props: ({data: {users, loading}}) => {
    console.log(users);
    return {
      loading,
      users,
    }
  }
})(UserList);

I can query users through the graphiql tool, but users is undefined when I console log users at the client side. Why is that? Do I need to do anything with Meteor account, such as publishing all users first? but I thought apollo does not depend on the Meteor pub-sub.

Thanks!

How are you console.log-ing it?

I console log in the props function. Please see my edited code. Thank you very much for your prompt response.

the resolver

Query: {
    async users(root, args, context) {
      return await Meteor.users.find().fetch();
    },
}

It should log twice - once as undefined with loading = true, and once with the data. Is the request coming back from the server? You can look in your Chrome Network tool to inspect the requests sent to the GraphQL server.

1 Like

Thank you @sashko, I found the bug. It needs to specify the subfield of the email field to get the query response back.

How did you fix the issue? Can you elaborate for others’ benefit?