GraphQL variables in GET request?

Hey guys, I’m having a bit of trouble understanding how to implement variables in GraphQL. I have it working on the removeUser function, but unsure as to how to grab the role from the user in the hook before mapping over it. I have the route setup so it is expecting a role parameter being a string.

You can see what I’m trying to do here at the top by providing the variables object, but of course data is not defined.

import React from 'react';
import { useUsersQuery, useRemoveUserMutation } from '../generated/graphql';
import { RouteComponentProps } from 'react-router-dom';

export const Admin: React.FC<RouteComponentProps> = ({ history }) => {
  const { data, loading, error } = useUsersQuery({
    fetchPolicy: 'network-only',
    variables: {
      role: data?.users.role,
  const [removeUser] = useRemoveUserMutation();

  if (loading) {
    return <div>Loading...</div>;

  if (error) {
    return <div>You are not the admin — unauthenticated.</div>;

  if (!data) {
    return <div>No data</div>;

  return (
      <h1>Admin Page</h1>

        { => {
          return (
              onClick={async (e) => {
                const response = await removeUser({
                  variables: {

                if (response) {
                  console.log(`Removed User:${} ID:${}`);
              {}, {}

Now that I’m looking at it, I was thinking maybe I have to pass the ID in the function to know who it is, but that wouldn’t really make sense either. I basically just want to read from the users table in my DB if the role of the user is set to “admin” or not. So it isn’t dependent on any ID besides the role.

Here is the backend query, not sure if I need it to be a mutation? But in the GraphQL playground this is working when I pass in the “admin” string as a parameter and will be rejected if anything but.

  // Query for all users
  @Query(() => [User])
  // @UseMiddleware(isAuth)
  async users(@Arg('role') role: string) {
    if (role !== 'admin') {
      throw new Error('Unauthenticated');
    } else {
      return User.find();