-1

For example, I have the following:

first_count = 5000
query = '''
{
   students(first: first_count) {
      id
      firstName
      college {
         id
         name
         location
         rating
      }
   }
}
'''

In the second line of the query, the first_count is supposed to be a variable but I am unfortunately having a hard time making it dynamic. I wanted to do an f string, but I am losing the multi line string to and also using escape characters. Is there any way to insert a variable in this string to make it dynamic, while keeping the multi-line format?

1
  • is this a graphql query? You probably don't need to use string interpolation (and probably shouldn't, since it is brittle) Commented Sep 13, 2024 at 20:24

1 Answer 1

0

Yes, you could solve it this way:

first_count = 5000
query = f'''
{{
  students(first: {first_count}){{
      id
      firstName
      college {{
         id
         name
         location
         rating
     }}
   }}
}}
'''

print(query)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.