Giter VIP home page Giter VIP logo

Comments (2)

maticzav avatar maticzav commented on May 24, 2024 5

Instead of defining feed- field resolver, you should define feed type resolver.

// Feed.ts
import { Context } from '../utils'

export const Feed = {
   async links(parent, args, ctx: Context, info) {
      return ctx.db.query.links({}, info)
   },
   async count(parent, args, ctx: Context, info) { // <- C (parent argument)
      const connections = await ctx.db.query.linksConnection({} , ` { aggregate { count } } `)
      return connections.aggregate.count
   }
}

// resolvers.ts
import { Feed } from './Feed'

export const resolvers = {
   Query: {
      feed: () => ({}), // <- A
   },
   Feed,
}

🤞 everything's ok, I have written it here 😄

Bit of explanation:

  • what A does is pass no property to Feed resolver. If we were to pass any property down, a: 'foo', for example, like this feed: () => ({ a: 'foo' }), the parent argument (C) would, instead of {} have value { a: 'foo' }.

from prisma-binding.

marktani avatar marktani commented on May 24, 2024 1

The answer is to return an object with two fields links and count. The links field is another resolver again:

async function feed(parent, args, ctx, info) {
  const allLinks = await ctx.db.query.links({})
  const count = allLinks.length
  const queriedLinkes = await ctx.db.query.links({ }) // don't pass info!

  return {
    links: queriedLinkes,
    count
  }
}

from prisma-binding.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.