Can I change graphs or use different queries for a graph based on custom variable?

Sure, create dashboard variable, e. g. key value variable, where you store that whole query - you must be careful when crrating that syntax - escaping all characters which may be causing a problem.

Then use that variable (raw value) as panel query.