[Vuejs]-Is it possible to dynamically replace the fields in a graphql/apollo query as well as variables?

0👍

Yep, it’s possible. With the graphql decorator, the template literal still replaces placeholders (eg ${expression}). For example

 let q_values = "datetime, value10, value11"
 const GET_VALUES = gql`
   query getValues (
     $date_begin: String!
     $date_end: String!
   ) {
       production (order_by: {datetime: desc}, 
                     where: {value94: {_gt: "0"}, 
                     _and: {datetime: {_gt: $date_begin}, 
                     _and: {datetime: {_lt: $date_end}}}}
       ){
           ${q_values}
        }
    }
 `;

Edit: Also, since you’re using vue-apollo check out reactive query definition.

Leave a comment