I need a graphql client lib to run on node.js for some testing and some data mashup - not in a production capacity. I'm using apollo everywhere else (react-apollo
, apollo's graphql-server-express
). My needs are pretty simple.
Is apollo-client
a viable choice? I can find no examples or docs on using it on node - if you're aware of any, please share.
Or maybe I should/can use the reference graphql client on node?
Apollo Client should work just fine on Node. You only have to install cross-fetch because it assumes
fetch
exists.Here is a complete TypeScript implementation of Apollo Client working on Node.js.
Here is simple node js implementation.
'graphiql' client is good enough for development activities.
server.js
schema.js
In response to @YakirNa 's comment:
I can't speak to the other needs I described, but I have done a fair amount of testing. I ended up doing all of my testing in-process.
Most testing ends up being resolver testing, which I do via a jig that invokes the graphql library's
graphql
function with a test query and then validates the response.I also have an (almost) end-to-end test layer that works at the http-handling level of express. It creates a fake HTTP request and verifies the response in-process. This is all within the server process; nothing goes over the wire. I use this lightly, mostly for testing JWT authentication and other request-level behavior that's independent of the graphql request body.
If someone is looking for a JavaScript version: