Graphqurl:GraphQL的卷曲,带有自动完成和订阅

2021-01-06 21:10:04

gq https:// my-graphql-endpoint / graphql \ -H'授权:Bearer< token> ' \ -q'查询{表{列}}'

$ gq< endpoint> [-H< header:value>]输入查询,使用TAB自动完成,按Ctrl + Q执行,按Ctrl + C取消gql>

您可以使用TAB触发自动完成。 Ctrl + C取消输入,Ctrl + Q / Enter执行查询。

gq<端点> \ -v' name = hasura' \ -q' mutation($ name:String){table(object:[{name:$ name}])}'

-n,--name = name:要执行的graphql定义的名称,仅当存在多个定义时使用

const {query} = require(' graphqurl');函数successCallback(response,queryType,parsedQuery){if(queryType ===' subscription'){//处理订阅响应} else {//处理查询/变异响应}}函数errorCallback(error,queryType, parsedQuery){控制台。错误(错误); }查询({查询:'查询{表{列}}'端点:' https:// my-graphql-endpoint / graphql'标题:{' x-access-key&#39 ;:' mysecretxxx'}},successCallback,errorCallback);

const {query} = require(' graphqurl');查询({查询:'查询{表{列}}'端点:' https:// my-graphql-endpoint / graphql'标头:{' x -access-key&#39 ;:' mysecretxxx',}})。然后((response)=>控制台。log(response))。 catch((错误)=>控制台。error(错误));

const {query} = require(' graphqurl');查询({查询:'订阅{表{列}}&#39 ;,端点:' https:// my-graphql-endpoint / graphql'标头:{' x -access-key&#39 ;:' mysecretxxx',}})。然后((observable)=> {observable。subscription((event)=> {控制台。log(' Event收到:',event); //处理事件},(error)=> ; {console.log(' Error:&#39 ;, error); //处理错误})}))。 catch((错误)=>控制台。error(错误));

successCallback:[函数]成功响应后调用成功的回调。使用以下参数调用它:

errorCallback:[功能]错误回调,在发生错误后调用。使用以下参数调用它:

返回:[Promise(response)]如果未提供successCallback和errorCallback,则此函数返回包装在promise中的响应。响应:响应是在查询和突变情况下符合GraphQL的JSON对象。但是,如果您进行订阅,它将返回一个观察值,您以后可以进行订阅。检查此示例以了解如何订阅可观察对象。

const {query} = require(' graphqurl');查询({查询:`查询($ name:字符串){表(其中:{列:$ name}){id列}}`,端点:' https:// my-graphql-endpoint / graphql&# 39;标题:{' x-access-key&#39 ;:' mysecretxxx'};变量:{name:' Alice'}}))。然后((response)=>控制台。log(response))。 catch((错误)=>控制台。error(错误));

const {query} = require(' graphqurl');查询({查询:`变异($ id_insert_input:字符串!,$ column_insert_input:字符串!){insert_to_table(id:$ id_insert_input,列:$ column_insert_input){ -graphql-endpoint / graphql',标头:{' x-access-key&#39 ;:' mysecretxxx',},变量:{id_insert_input:' id_ak23sdfkjk2' ,column_insert_input:' Bob'}})。然后((response)=>控制台。log(response))。 catch((错误)=>控制台。error(错误));

const {query} = require(' graphqurl'); const eventCallback =(event)=> { 安慰 。日志('收到事件:&#39 ;,事件); //处理事件}; const errorCallback =(错误)=> { 安慰 。日志(' Error:',error)};查询({查询:'订阅{表{列}}&#39 ;,端点:' https:// my-graphql-endpoint / graphql'标题:{' Authorization& #39 ;:' Bearer Andkw23kj = Kjsdk2902ksdjfkd'}})。然后((observable)=> {observable。subscription((event)=> {控制台。log(' Event receive',event); //处理事件},(error)=> {控制台日志(' Error&#39 ;, error); //处理错误})}))。 catch(errorCallback);

const {query} = require(' graphqurl');函数eventCallback(event){控制台。日志('收到事件:&#39 ;,事件); //处理事件}函数errorCallback(错误){控制台。日志(' Error:',错误)}查询({查询:'订阅{表{列}}'端点:' https:// my-graphql -endpoint / graphql&#39 ;,标头:{' Authorization&#39 ;:' Bearer Andkw23kj = Kjsdk2902ksdjfkd'}},eventCallback,errorCallback);

gq \ https:// my-graphql-endpoint / graphql \ -H'授权:Bearer< token> ' \ -H' X-另一个标题:另一个标题值' \ -v' variable1 = value1' \ -v' variable2 = value2' \ -q'查询{表{列}}'

gq \ https:// my-graphql-endpoint / graphql \ -H'授权:Bearer< token> ' \ -H' X-另一个标题:另一个标题值' \ --variablesFile =' ./ queryVariables.json' \ --queryFile =' ./ query.gql