javascriptgraphqlgraphql-jstemplate-literalstagged-templates

How to get qql expression from String


I have a String variable with GraphQL query. I want to write function which will return this the gql tag. Could you help me to write it. For example:

Input:

let input = `query { employee { id surname } }`;

Output:

let output = gql`query { employee { id surname } }`;

const getTagFromString = (input) => {  ?????   };

let output = getTagFromString(input);

useQuery(output);

Solution

  • You can write

    let input = "query { employee { id surname } }";
    let output = gql([input]);
    
    useQuery(output);