The Shimano GRX levers use the 11-speed "road" cable pull ratio (yes, even for 10 speeds the new groups like GRX and Tiagra 4700 use the 11-speed ratio even though they might have 10 speeds only on the shifter).
A Shimano Deore XT rear derailleur might use anything from:
- Traditional Shimano pull ratio (if intended for 6-9 speed groups)
- Shimano 10-speed "MTB" pull ratio (if intended for 10-speed groups)
- Shimano 11-speed "MTB" pull ratio (if intended for 11-speed groups, very similar but not identical to the 10-speed "MTB" ratio)
- Shimano 12-speed "MTB" pull ratio (if intended for 12-speed groups)
I understand that the 12-speed "MTB" groups also use pull ratio very similar to the 10-speed and 11-speed "MTB" pull ratios.
So it doesn't work. The only way you could make it work is using some kind of gadget that translates the pull ratio within the cable system. Such gadgets make the cable bend in a very small bending radius so I suppose such a gadget would cause rapid cable fatigue. Also such gadgets are often nearly as (or even more) expensive as a new derailleur that uses the proper ratio directly.
In your case, you might have a reason for using such a gadget. However, before doing so I advise you to test how well the GRX rear derailleur works with a 11-46 cassette for example (however the only 11-speed Shimano 11-46 cassettes seem to have a very large jump from second easiest gear to easiest gear and the rest uniformly spaced -- perhaps some other manufacturer might offer a 11-46 cassette with evenly spaced ratios). You might be surprised at how well it might work even though it may not be officially supported.
Also I'm very surprised if 40t chainring and 42t rear sprocket with regular sized wheels would be too hard gear. I have a bike with 36t little ring and 30t rear sprocket and I never ever use the smallest gear in this bike. However, I do understand the need for larger gear range -- 40t chainring would mean I have to use either 11t or 13t rear sprocket as my flatland gear and either of these choices has the chain in such a small radius that efficiency suffers. The 11t and 13t sprockets should be "emergency hard gears" that are used only on the rare occasions of wanting to go very fast in a favorable wind. In normal cycling, it is advised to limit to 15t or bigger sprockets for increased chain life and better drivetrain efficiency.