Is it still ok to ask nexus questions here btw? I'...
# orm-help
s
Is it still ok to ask nexus questions here btw? I'm curious if it's somehow possible that custom field resolver are only triggered if a field is actually being requested? By default it seems like all fields are being resolved..
As an example, I do something like this:
Copy code
t.int("assignments_count", {
      resolve(root, _args, ctx) {
        return ctx.prisma.assignment.count({
          where: {
            formPrototypeId: root.id,
          },
        });
      },
    });
But I don't want this to actually resolve / do anything when the assignments_count field is not requested as part of the query.
r
@Sascha 👋 I tried adding a custom field and it’s only triggered when called.
What’s the version of Nexus you’re using?
This is my object and Query:
Copy code
const User = ns.objectType({
  name: 'User',
  definition(t) {
    <http://t.nonNull.int|t.nonNull.int>('id')
    t.nonNull.string('name')
    t.field('total', {
      type: 'Int',
      resolve(_parent, _args, ctx) {
        console.log('called')
        return ctx.prisma.user.count()
      },
    })
  },
})

const Query = ns.queryField((t) => {
  t.list.field('users', {
    type: 'User',
    resolve(_root, _args, ctx) {
      return ctx.prisma.user.findMany()
    },
  })
})
I have added a log in the custom field and it only logs when the field is explicitly stated in the Playground
s
Copy code
1.0.0
That's weird, I'll triple check this again.
💯 1
r
@Sascha 👋 Were you able to find the issue?
s
I unfortunately didn't. But as I migrated our complete API away from GraphQL to REST API it's not really a problem anymore, at least for me 🙂