Strapi is `undefined`

System Information
  • 4.12.5:
  • OSX:
  • Postgres 15:
  • 18.16.0:

According to the docs I’m implementing policies in graphql. I have the following in src/index.js:

register({ strapi }) {
    const extensionService = strapi.service("plugin::graphql.extension");

    extensionService.use({
      resolversConfig: {
        'Mutation.createRegistration': {
          policies: [
            // Make sure the user is using his own id
            async (context, { strapi }) => {
              const loggedInUserId = context.state.user.id;
              const targetedUserId = context.args.data.users_permissions_user;

              if (parseInt(loggedInUserId) === parseInt(targetedUserId)) {
                return true
              } else {
                throw new PolicyError('You are only allowed to make reservations for yourself!', {
                  policy: 'is-same-user',
                });
              }
            },

            // Make sure there's a spot available
            async (context, { strapi }) => {
              console.dir(strapi)
              const activity = await strapi.db.query('api::activity.activity').findOne({
                where: { id: context.args.data.activity },
                select: ['registrations_cap', 'registrations']
              })

              console.dir(activity)

              return true
            },
          ]
        }
      }
    })

Now the second policy, I want to make sure there’s a spot available, if not, return false. To do that I’m quering the db, but strapi is undefined while the docs clearly state it should be there:

What am I missing?

1 Like