How do you create a template with replaceable variables for JS/React?

How do you create a template with replaceable variables for JS/React?


0

Context:

  1. I want to create a GraphQL query template with different variables that I can replace with key/values from another dictionary
  2. I want to give JS/React this template and dictionary and be able to replace the variables in the template with the corresponding values in the dictionary

How would you recommend I do this?

One idea is to represent the GraphQL templates as txt files and use JS string interpolation.

query {
  pets {
    ${some_replaceable_attribute}
    ${another_replaceable_attribute}
  }
}

And have JS do all the token replacements.

Do you have any other suggestions on how I should do this?

Thank you!


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *