Query nested array

default discord avatar
danielkraemer
3 weeks ago
3

So a part of my user object looks like this:



{
      name: 'sites',
      label: 'Seitenrechte',
      saveToJWT: true,
      required: false,
      type: 'array',
      access: {
        // Only admins can create or update a value for this field
        create: isAdminFieldLevel,
        update: isAdminFieldLevel,
      },
      admin: {
        condition: ({ isSystemAdmin }) => !isSystemAdmin,
        description: 'This field sets which sites that this user has access to.',
      },
      fields: [ // required
        {
          name: 'siteId',
          type: 'relationship',
          relationTo: 'sites',
          required: true,
          access: {
            // Only admins can create or update a value for this field
            create: isAdminFieldLevel,
            update: isAdminFieldLevel,
          },
        },
        {
          name: 'role',
          // Save this field to JWT so we can use from `req.user`
          saveToJWT: true,
          type: 'select',
          hasMany: false,
          defaultValue: 'editor',
          access: {
            // Only admins can create or update a value for this field
            create: isAdminFieldLevel,
            update: isAdminFieldLevel,
          },
          required: true,
          options: [
            {
              label: 'Admin',
              value: 'admin',
            },
            {
              label: 'Editor',
              value: 'editor',
            },
            {
              label: 'API',
              value: 'api',
            },
          ],
        },
      ],
    },


As my user sites relationship is an object not an array I don't think that the demo example works for me, but I didn't tried it yet



While trying to understand the query from the access-control-demo, I tried writing a graphql query and encountered a problem



query {
  Users(where:
        {
        sites__site: { in: ["SITEID"] },
        sites__role: {equals: admin}
      }) {
    docs {
      email,
      firstName,
      sites {site{title}}
    }
    totalDocs
  }
}


I need to know if the user has a configuration for the given SITEID AND has role admin for this page. But how do I query this?



ok. figured out that this won't work 😄

    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.