graphqlapollo-serverexpress-graphqlreact-admin

apollo graphql schema react-admin beginner


Brand new to these technologies and am pretty pumped by what i see so far, i am having a rough time finding an example of something i am stuck on. The docs for react-admin suggest my schema for say Posts follows the allPosts and _allPostsMeta.. The allPosts part works no problem but naturally react-admin chokes to death on the _allPostsMeta because i am not sure how that fits into things.. Examples mostly just show what your schema should look like but don't go any further than that.. Is there a demo server app setup like this anywhere that one could look at? I have my resolvers setup using join monster presently and that all makes decent sense to me, so i guess my question is, could anyone tell me, or point me to what my resolver should look like to satisfy that _allPostsMeta query that returns ListMetadata.. i looked into a few things like resolver chaining thinking maybe i am supposed to just return the length of the Post[] from allPosts but maybe that is overcomplicating things.. Any help or explanations would be greatly appreciated...

Thanks


Solution

  • appreciate this is an old question and you've probably moved on but thought I'd put a response here as I hit a similar situation myself whilst trying to implement a React-Admin front-end with an Apollo-Server-Express GraphQL back-end.

    Based on the React Admin example of ra-data-graphql-simple (https://github.com/marmelab/react-admin/tree/master/packages/ra-data-graphql-simple)

    My resolver ended up looking as follows:

    Query: {
        _allPostsMeta: (parent, args, { db }, info) => db.post.findAndCountAll()
    }
    

    Note findAndCountAll() not findAll() as I've seen in other examples. This was enough to get React Admin pagination working for me so far. The lack of documentation / examples for all of this does make me somewhat dubious that this software is not the way to go or has been surpassed by something else.