How to pass a variable to GraphQL query?

I have a query where I am trying to obtain the id and name for a board item based on a column value. I am trying to pass the variable $name to the query like this:

$name = “Test Practice Full Service”;

$query = 'query ($name: String!){
  items_by_column_values (board_id: 3873753003, column_id: "name", column_value: $name) {
	id
	name
  }
}';

However, I get an error message:

Variable $name of type String! was provided invalid value

what am I doing wrong here, and how should I structure this query so that I can pass the $name variable into the query?

firstly I would avoid the items_by_column_values as it will be removed on January 15th, 2024 (8 weeks) from the available API versions. (2023-07, the last version to support it, will be discontinued).

Going forward use items_page but don’t forget to set the API-Version header to 2023-10 until at least January 15. 2024 when API 2024-01 becomes default where this is no longer needed to support items_page.

query ($itemName: CompareValue!, $boardId: [ID!]) {
  boards(ids: $boardId) {
    items_page(query_params: {rules: {column_id: "name", compare_value: $itemName}}) {
      items {
        id
        name
      }
    }
  }
}

//variables are sent separately of course, in the variables of the request
{
  "itemName": "Test Practice Full Service",
  "boardId": ["3873753003"]
}

Alternatively use items_page_by_column_value:

query ($itemName: [String]!, $boardId: ID!) {
    items_page_by_column_values(board_id: $boardId, columns: {column_id: "name", column_values: $itemName}) {
      items {
        id
        name
      }
    }
  }

//variables are sent separately of course, in the variables of the request
{
  "itemName": "Test Practice Full Service",
  "boardId": "3873753003"
}

Note the change of the board ID to a string, instead of Int. ID technically can support both, but string is probably preferred because that is also how IDs are returned for boards and items by the API. (in other words, don’t make things harder for yourself)