35 lines
802 B
JavaScript
35 lines
802 B
JavaScript
const http = require('http');
|
|
|
|
const data = JSON.stringify({
|
|
query: 'query { serverInfo { version } }'
|
|
});
|
|
|
|
const options = {
|
|
hostname: '127.0.0.1',
|
|
port: 3000,
|
|
path: '/graphql',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
'apollo-require-preflight': 'true',
|
|
'Content-Length': Buffer.byteLength(data)
|
|
}
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
console.log(`STATUS: ${res.statusCode}`);
|
|
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
|
res.setEncoding('utf8');
|
|
let body = '';
|
|
res.on('data', (chunk) => { body += chunk; });
|
|
res.on('end', () => { console.log(`BODY: ${body}`); });
|
|
});
|
|
|
|
req.on('error', (e) => {
|
|
console.error(`problem with request: ${e.message}`);
|
|
});
|
|
|
|
req.write(data);
|
|
req.end();
|