dot-http icon indicating copy to clipboard operation
dot-http copied to clipboard

Better experience for GraphQL requests

Open bayne opened this issue 5 years ago • 0 comments

Attempting to create requests for a GraphQL server leads to some nasty syntax: https://github.com/bayne/dot-http/issues/9#issuecomment-586509962

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)

bayne avatar Feb 15 '20 19:02 bayne