Need to pass variable in custom DQL query

Hello,
I use custom DQL query for graphql which schema as below

type ReturnData @remote {
  name: String
  count: Int
}
type Attributemap @remote {
  groupby: [ReturnData] @remoteResponse(name: "@groupby")
}
type Query {
  queryAttribute(attr: String!): [Attributemap] @custom(dql: """
    query q($attr: string) {
      queryAttribute(func: type(Product)) @groupby(name:Product.$attr) {
        count(uid)
      }
    }"""
  ),
}

Here i want to use same query for group by any Product type parameters. for that i use $attr variable as below which is not working while execute DQL query.
White run below DQL query it’s return correct results.

queryAttribute(func: type(Product)) @groupby(name:Product.cost) {
   count(uid)
}

Here also need to pass DQL filter variables @filter(eq(Product.name,"ABC")..) as dynamically.