【问题标题】:How to get qql expression from String如何从String中获取qql表达式
【发布时间】:2020-07-06 12:27:33
【问题描述】:

我有一个带有 GraphQL 查询的字符串变量。我想编写一个函数来返回这个 gql 标签。能不能帮我写一下。例如:

输入:

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

输出:

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

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

let output = getTagFromString(input);

useQuery(output);

【问题讨论】:

    标签: javascript graphql graphql-js template-literals tagged-templates


    【解决方案1】:

    你可以写

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 2011-07-30
      • 2020-05-10
      • 2018-09-03
      相关资源
      最近更新 更多