I'm trying to use highland in combination with the heroku-client. But internally in the heroku client it uses this, even if I try to bind to bind this, the function gives and error message where there is a refrance to this I'm not able to get it to work.
Right no the code looks like this
const Heroku = require('heroku-client');
const hl = require('highland');
var hk = new Heroku({
token: process.env.HEROKU_API_TOKEN
});
var list = hl.wrapCallback(hk.apps().list.bind(hk));
list().toArray((a) => 'console.log(a)')
So this code snippet fails with the following error message:
...node_modules/heroku-client/lib/resourceBuilder.js:35
if (this.params.length !== pathParams.length) {
^
TypeError: Cannot read property 'length' of undefined
Yo! :-)
You're binding to hk and not what hk.apps() return, which is what the list function depends on (it's a member of what hk.apps() returns)
Try this:
const Heroku = require('heroku-client');
const hl = require('highland');
const hk = new Heroku({
token: process.env.HEROKU_API_TOKEN
});
const hkApps = hk.apps();
const list = hl.wrapCallback(hkApps.list.bind(hkApps));
list().toArray((a) => 'console.log(a)')
Related
Good Morning! I am currently working on a discord bot but I am facing an issue with the event handlers.
There seems to be a problem with the "get" command but I can't seem to find out what it
is, I have given the code below to my message.js
module.exports = (Discord, client, msg) => {
const prefix = 'e!';
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command)
if (!cmd){
msg.channel.send("That is not an available command!")
};
if(command) command.execute(client, msg, args, Discord);
};
The code below is my index.js
const Discord = require("discord.js")
const client = new Discord.Client({intents : ["GUILDS", "GUILD_MESSAGES"]});
const button = require('discord-buttons')(client)
const { MessageButton } = require("discord-buttons")
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
client.login(process.env.token)
Any help would be greatly appreciated!
I fixed it! It seems that the order in which Discord and client were (in here).
module.exports = (Discord, client, msg)
was wrong! Instead, I swapped Discord around with client and it seems to work!
module.exports = (client, Discord, msg)
If anyone can tell me why this happens (as I would love to learn more)
You can comment or answer!
There was also an error with the execute command which I also fixed
if(cmd) {
cmd.execute(client, msg, args, Discord);
}
Thanks everyone for their contribution! Really needed your help!
I'm trying to use sinon-chai with expect but when I try to check if a function is not called, I get:
TypeError: expect(...).to.have.not.been.called is not a function
This is what I tried:
expect(createCompany).not.to.have.been.called();
expect(createCompany).to.not.have.been.called();
expect(createCompany).to.have.not.been.called();
expect(createCompany).to.have.been.not.called();
expect(createCompany).to.have.been.notCalled();
But none of them is working, but I have no problem without the ".not"
My file is starting with:
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
const { expect } = chai;
Ok so I found that this is because of the parens.
So just replace called() by called and it's working.
i was going through a GraphQL tutorial from udemy,
https://www.udemy.com/introduction-to-graphql-and-apollo-building-modern-apis
And i was going through the guide to operating graphql and graphiql -> apollo -express - server. And got this. This particular error has not been defined in the videos. It is a free tutorial and lecture 9 has this.
Wht to do. i find no solution. Please help.
TypeError: Cannot read property 'startsWith' of undefined
at Object.renderGraphiQL (/home/dell/Desktop/graphql-
tutorial/node_modules/apollo-server-module-
graphiql/src/renderGraphiQL.ts:48:17)
at Object. (/home/dell/Desktop/graphql-tutorial/node_modules/apollo-
server-module-graphiql/src/resolveGraphiQLString.ts:62:10)
at step (/home/dell/Desktop/graphql-tutorial/node_modules/apollo-
server-module-graphiql/dist/resolveGraphiQLString.js:32:23)
at Object.next (/home/dell/Desktop/graphql-
tutorial/node_modules/apollo-server-module-
graphiql/dist/resolveGraphiQLString.js:13:53)
at fulfilled (/home/dell/Desktop/graphql-tutorial/node_modules/apollo-
server-module-graphiql/dist/resolveGraphiQLString.js:4:58)
at
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
renderGraphiQLString.js
This is the line it says has error -->
export function renderGraphiQL(data: GraphiQLData): string {
const endpointURL = data.endpointURL;
const endpointWs =
endpointURL.startsWith('ws://') || endpointURL.startsWith('wss://');
const subscriptionsEndpoint = data.subscriptionsEndpoint;
const usingHttp = !endpointWs;
const usingWs = endpointWs || !!subscriptionsEndpoint;
const endpointURLWs =
usingWs && (endpointWs ? endpointURL : subscriptionsEndpoint);
resolveGraphiQLString.js
export async function resolveGraphiQLString(
query: any = {},
options: GraphiQLData | Function,
...args
): Promise<string> {
const graphiqlParams = createGraphiQLParams(query);
const graphiqlOptions = await resolveGraphiQLOptions(options,
...args);
const graphiqlData = createGraphiQLData(graphiqlParams,
graphiqlOptions);
return renderGraphiQL(graphiqlData);
}
server.js
import express from 'express';
import {graphqlExpress,graphiqlExpress} from 'apollo-server-express';
import bodyParser from 'body-parser';
import schema from './schema.js'
const server = express();
server.use('/graphql', bodyParser.json(), graphqlExpress(schema));
server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql'
}));
server.listen(4000,() =>{
console.log('listening on port 4000');
});
I was doing the same tutorial and got stuck with the same error. I just now got it working. For me, I had spelled endpointURL as endpointUrl because it seems stupid to me to capitalize acronyms within camel-case, but of course this being a specific key, it has to be spelled right.
For you, the only difference I see in the code is that I think you should pass {schema} to graphqlExpress, but you're passing just schema. So here's how I have it:
server.use("/graphql", bodyParser.json(), graphqlExpress({ schema }))
Your code is not correct. In order to define the graphiql endpoint you need to do this in the following way:
const server = express();
server.use('/graphql', bodyParser.json(), graphqlExpress(schema));
server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
Keep in mind you should pass to the graphiqlExpress method the endpointURL of your real graphql endpoint.
Cheers!
I can get the test to run on the cloud, but it is failing. However, it works local. I think it is because I don't have the right server address. I tried myserver.bluemix.net, localhost:5001 and the null that works local. I can't seem to find the address.
my unit test:
process.env.NODE_ENV = 'test';
var chai = require('chai');
var chaiHttp = require('chai-http');
var app = require('../index');
var cfenv = require('cfenv');
var should = chai.should();
var expect = chai.expect;
chai.use(chaiHttp);
describe('Conversation', function() {
var serviceBaseUrl = '';
if (process.env.test_env == 'cloud') {
serviceBaseUrl
= 'http://' + '127.0.0.1:5001';
}
it ('should return message', function(done){
chai.request(app)
.post(serviceBaseUrl + '/api/v1/conversation')
.send({input: "test", ConverationId: ""})
.end(function (err, res) {
res.status.should.equal(200);
console.log(res.body);
done();
});
});
});
this is the error:
Server running at http://127.0.0.1:5001
Conversation
1) should return message
double callback!
0 passing (33ms)
1 failing
1) Conversation
should return message:
Uncaught TypeError: Cannot read property 'status' of undefined
at test/test-conversation.js:27:12
at Test.Request.callback (/home/pipeline/79a4adb4-e686-494a-9974-3c5860240fcb/node_modules/superagent/lib/node/index.js:615:12)
at ClientRequest.<anonymous> (/home/pipeline/79a4adb4-e686-494a-9974-3c5860240fcb/node_modules/superagent/lib/node/index.js:567:10)
at Socket.socketErrorListener (_http_client.js:309:9)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
If this is a unit test, you should use mocks in order to isolate your testing environment. The problem is that your localhost is going to have a different base url than when your app is deployed to the cloud.
Consider using a library like nock to mock your api requests.
If you are doing and/or want to do integration tests, you can set the base url with something like this:
const base = process.env['ROUTE'] || 'http://localhost:3000/route';
(Where process.env['ROUTE'] could be something like 'https://app.mybluemix.net/route'.)
According to this Hapi JS plugin's documentation, The RethinkDB library and the connection are bound to the server context inside handlers on this.rethinkdb and this.rethinkdbConn.
However, I'm not being able to access those, only using request.server.plugins etc. Does anyone know why? Is it because the context set inside a plugin with server.bind() is only available inside the plugin itself ? Thanks!
EDIT:
Here's is some of the code on index.js
const plugins = [{register: require('hapi-rethinkdb'), options: {url: //url here}]
server.register(plugins, () => {
server.route(require('./routes'))
server.start()
})
The on routes.js, let's say a have a route like this:
{
method: 'GET',
path: '/list-of-things',
handler: function(request, reply) {
// I have to use it like this:
const r = request.server.plugins['hapi-rethinkdb'].rethinkdb;
const connection = request.server.plugins['hapi-rethinkdb'].connection;
// Because this throws undefined:
const r = this.rethinkdb;
const connection = this.rethinkdbConn
}
}