What is a good way of loading a graphql template whose values needs to be filled. Any standard library?

I want to write a python tool to create Synthetic Monitors in NewRelic, I have created a template

mutation {
  syntheticsCreateScriptApiMonitor (
    accountId: {account_id}, 
    monitor: { 
      locations: { public: {locations} },
      name: "{monitor_name}", 
      period: {period},
      runtime: {
        runtimeType: "{runtime_type}",
        runtimeTypeVersion: "{runtime_version}",
        scriptLanguage: "{script_language}"
      },
      script: "{script_content}", 
      status: "{status}",
      advancedOptions: { enableScreenshotOnFailureAndScript: {enable_screenshot} },
      apdexTarget: {apdex_target}
    }
  ) {
    errors {
      description
      type
    }
  }
}

which I want to load into my code and fill it with the required values for account_id, locations and so on.

I wrote this

import yaml
from gql import gql

def load_config(filename):
    """ Load configuration from YAML file """
    with open(filename, 'r') as file:
        return yaml.safe_load(file)

def load_graphql_template(filename):
    """ Read GraphQL template from a specified file """
    with open(filename, 'r') as file:
        return file.read()

def load_script_content(filename):
    """ Load script content from file (for scripted monitors) """
    with open(filename, 'r') as file:
        return file.read()

# Generate the mutation with the provided configuration and monitor type
def generate_mutation(config):
    monitor_type = config.get('MONITOR_TYPE', 'scripted')  # Default to 'scripted' if not specified
    
    # Determine the template file name based on monitor type
    template_filename = f'synthetic-monitor-templates/{monitor_type}_monitor_template.graphql'
    
    # Load the GraphQL template from the specified file
    template = load_graphql_template(template_filename)
    
    script_content = load_script_content(config['SCRIPT_FILE_PATH']).replace('n', '\n')  # Escape newlines in the script content
    
    if monitor_type == 'scripted_browser':
        mutation = template.format(
            account_id=config['ACCOUNT_ID'],
            monitor_name=config['MONITOR_NAME'],
            period=config['PERIOD'],
            runtime_type='BROWSER',
            runtime_version=config['RUNTIME_VERSION'],
            script_language=config['SCRIPT_LANGUAGE'],
            script_content=script_content,
            status=config['STATUS'],
            enable_screenshot=str(config['ENABLE_SCREENSHOT']).lower(),
            apdex_target=config['APDEX_TARGET'],
            locations=str(config['LOCATIONS']).replace("'", '"')  # Convert list to JSON array format
        )
    elif monitor_type == 'scripted_api':
        mutation = template.format(
            account_id=config['ACCOUNT_ID'],
            monitor_name=config['MONITOR_NAME'],
            period=config['PERIOD'],
            runtime_type='NODE_API',
            runtime_version=config['RUNTIME_VERSION'],
            script_language=config['SCRIPT_LANGUAGE'],
            script_content=script_content,
            status=config['STATUS'],
            enable_screenshot=str(config['ENABLE_SCREENSHOT']).lower(),
            apdex_target=config['APDEX_TARGET'],
            locations=str(config['LOCATIONS']).replace("'", '"')  # Convert list to JSON array format
        )
    elif monitor_type == 'scripted':
        mutation = template.format(
            account_id=config['ACCOUNT_ID'],
            monitor_name=config['MONITOR_NAME'],
            period=config['PERIOD'],
            runtime_type=config['RUNTIME_TYPE'],
            runtime_version=config['RUNTIME_VERSION'],
            script_language=config['SCRIPT_LANGUAGE'],
            script_content=script_content,
            status=config['STATUS'],
            enable_screenshot=str(config['ENABLE_SCREENSHOT']).lower(),
            apdex_target=config['APDEX_TARGET'],
            locations=str(config['LOCATIONS']).replace("'", '"')  # Convert list to JSON array format
        )
    elif monitor_type == 'ping':
        mutation = template.format(
            account_id=config['ACCOUNT_ID'],
            monitor_name=config['MONITOR_NAME'],
            period=config['PERIOD'],
            url=config['URL'],
            status=config['STATUS'],
            enable_screenshot=str(config['ENABLE_SCREENSHOT']).lower(),
            locations=str(config['LOCATIONS']).replace("'", '"')  # Convert list to JSON array format
        )
    else:
        raise ValueError(f"Unsupported monitor type: {monitor_type}")

    return gql(mutation)

But I keep getting key error because the graphql template is not being loaded correctly, with spaces, or newlines causing issues. There is no standard lib for graphql like yaml. So what could be a good way around this??

I have tried cleaning up the graphql template so that it would load correctly

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật