Fetching data from graphql with express-graphql and HTTP client -


im having difficulty making http fetch request on standard apollo graphql-server-express

i've tried following guidance on graphql.org no avail.

just test this, using fusetools news feed example , switching out fetch call call apollo-server using standard http:

```

fetch('https://localhost:8080/graphql', {                 "method": 'post',                 "headers": { "content-type": "application/graphql", "accept": "application/json"},                 "body": {"query": "{ places { id name address city }" }             })             .then(function(response) { return response.json; })             .then(function(responseobject) { data.value = responseobject; }); 

```

this full code with returned fields changed.

```

<dockpanel>     <javascript>         var observable = require("fusejs/observable");          var data = observable();         fetch('https://localhost:8080/graphql', {             "method": 'post',             "headers": { "content-type": "application/graphql", "accept": "application/json"},             "body": {"query": "{ places { id name address city }" }         })         .then(function(response) { return response.json; })         .then(function(responseobject) { data.value = responseobject;                });           module.exports = {             datasource: data         };     </javascript>      <statusbarbackground dock="top" />     <bottomframebackground dock="bottom" />      <stackpanel dock="top">         <text fontsize="28" alignment="verticalcenter"             textalignment="center" padding="2"             value="news" />         <rectangle height="1" margin="0,3,0,0" fill="#333c48" />     </stackpanel>      <text ux:class="header" margin="10,10,10,5" textwrapping="wrap" fontsize="22" />     <text ux:class="article" margin="10,0,10,0" textwrapping="wrap" fontsize="13" />     <text ux:class="publisheddate" margin="10,0,10,0" fontsize="13" color="#999" />      <scrollview>         <stackpanel alignment="top">             <panel height="7" />             <each items="{datasource.data.places}">                 <panel ux:class="horizontalbar" margin="46,10,0,10"                         alignment="verticalcenter">                     <rectangle height="1" fill="#dcdee3" />                 </panel>                  <header value="{name}" />                 <article value="{address}" />                 <publisheddate value="{city}" />                 <horizontalbar />             </each>         </stackpanel>     </scrollview>  </dockpanel> 

``` guidance appreciated. thank you.

to use fetch graphql server, proper syntax worked in case following. thanks, daniel.

fetch('https://graphql-swapi.parseapp.com/', {   method: 'post',   headers: { "content-type": "application/json", "accept": "application/json"},   body: json.stringify({"query":"{allfilms {totalcount}}","variables":null,"operationname":null}) }).then(function(response) { return response.json(); }) .then(function(responseobject) { console.log('got', json.stringify(responseobject, null, '  ')); }); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -