bayne / dot-http

dot-http is a text-based scriptable HTTP client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better experience for GraphQL requests

bayne opened this issue · comments

Attempting to create requests for a GraphQL server leads to some nasty syntax:
#9 (comment)

Current plan for a response body generator:

POST {{base_url}}/graphql

< {%
  var query = '{\
    leftComparison: hero(episode: EMPIRE) {\
      ...comparisonFields\
    }\
    rightComparison: hero(episode: JEDI) {\
      ...comparisonFields\
    }\
    }\
    fragment comparisonFields on Character {\
      name\
      appearsIn\
      friends {\
        name\
      }\
  }';

  return {
    "query": query
  };
%}

> {% console.log(response); %}

Note the symmetry of the syntax:

  • < {% ... %} for a request body generator
  • > {% ... %} for a response handler (existing)