[Python] Best way to construct a GraphQL query string in Python

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to do this (see title), but it's a bit complicated since the string I'm trying to build has to have the following properties:

    • mulitiline
    • contains curly braces
    • I want to inject variables into it

    Using a normal '''''' multiline string makes injecting variables difficult. Using multiple f-strings makes injecting variables easy, but every curly brace, of which there are a lot, has to be doubled. And an f has to be prepended to each line. On the other hand, if I try using format, it also gets confused by all the curly braces.

    Is there a better way that I haven't considered yet?

    Continue reading...

Compartilhe esta Página