Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further fixes on pull #2 #3

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Conversation

ilearnio
Copy link

No description provided.

@nordsimon
Copy link
Owner

Nice. I'll take a look at it and get back to you soon

var results = self.trigger('request', [req])

// The 'request' hook may redefine response when returning something
for (var i = results.length; i--;) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure i like this part very much, it feels odd that a return from a trigger should change any execution. I can accept that you can mutate the req object but the return value should not be handled. What are you aiming for with this ?

Copy link
Author

@ilearnio ilearnio Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happened to need such a feature in a previous graphql client (called "lokka") that I used to use. I wanted to setup caching of non-mutating requests, but I already do so in my application level. So I personally don't need this feature at the moment, just felt it needs to be there, might come in use some day. Yet the module becomes full-featured, and now can be even extended by external plugins/modules (using hooks). I updated this code a bit

@nordsimon
Copy link
Owner

Hm, what happend with the error handling part after query result. When a query returns with errors i wanted it to throw to the catch block so the promise chain stops

@ilearnio
Copy link
Author

ilearnio commented Jul 27, 2016

In my API I'm throwing custom errors that I need to display in the HTML. So I need to get the response as is, regardless of whether it's an error or not. And since GraphQL is so "strong typed" I cannot return { error: 'Error ...' } from a resolver when the schema expects something like { foo: String! }. But it is possible to throw from within a 'data' hook if anyone needs so

@ilearnio
Copy link
Author

I also removed everything regarding of how errors should be treated (e.g. useful debugging info), since now everything could be done inside of hooks. So I guess it would be better to move such things apart to different modules and attach them using hooks


if (lineErrors.length) {
var errorHighlight = []
var req = self.options.request || {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make this to an actual request object Fetch API Request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Fixed this as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to switch back to plain req object since there were many problems with Request. For example, I couldn't pass headers to it when initializing the client because they could only be modified after the Request object is initialized. Also, I couldn't pass "credentials" to it, because of a bug in isomorphic-fetch. There were some other issues like a difference in behaviour between browser and Node, so it is just not the way to go

@@ -0,0 +1,15 @@
MOCHA_TARGET=test/specs.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove Makefile
use npm scripts
https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants