Hi folks,
a while ago I wanted to play with GraphQL and it was fun to learn and manually build a server. Early on I realised, running a GraphQL server is relatively complex primarily due to the amazing flexibility it provides to clients to formulate any type of nested queries and request selection of fields. Luckily, many projects are out there providing implementations and tools to assist in building a GraphQL server with ease.
Wouldn't it be awesome to be able to run a GraphQL server right into Node-RED too ?!
With this set of nodes you can run a query & mutation GraphQL server, and also run a GraphQL Subscription server !
Note: this node requires NodeJS version 11.15 or higher.
Please read the docs of the node before starting to work with it.
Here are summary of features
-
Uses Node-RED httpNode which means it inherits any middlewares, security,etc. you may have.
-
An option to use Dataloader which enables efficient query implementation resolving N+1 problem for nested operations inherent to any GraphQL server.
-
There are 3 modes to choose from to determine how you plan to resolve queries. Please read the docs to understand the differences.
-
includes a GraphQL Schema Visual editor, and GraphQL Voyager builds ! (I may remove those builds from future nodes but those are great for learning GraphQL if you are new)
-
includes a GraphQL Playground (previously I used Graphi) - the Playground enables you to test your query, mutation operations and interact with the server. The Playground also supports subscriptions!
-
Experimental feature to automatically resolve Pagination in your schema. This is supporting the unofficial GraphQL Cursor Pagination Specs
-
Subscription Server implementation based on graphql-subscriptions using MQTT for PubSub which means you can use the out of box MQTT nodes with it.
-
For testing and playing around, In the examples folder of the node, I included a sqlite database called chinook.sqlite chinook-database and created a GraphQL schema for it. Import the sample flow if you want to try it. Note, this is relatively a complex sample which includes Pagination. If you are new to GraphQL , create your own simple GraphQL schema without pagination and familiarise yourself first.
How to use it
-
Define a GraphQL schema using GraphQL schema language. (note syntax highlighting of GraphQL schema language is not working at the moment - if you are new to GraphQL use the included Visual GraphQL-Editor and it will generate a schema for you. Start by a simple schema.
-
Configure how you plan to resolve the queries and mutations, and decide whether to use Dataloader
-
Depending on what you choose for Resolvers mode, create flows which resolves your operations. Typically it starts with a Switch node which branches out to each type of operation you would resolve. The flow typically interacts with a backend database and returns the results back to clients.
-
Return the results to client using GraphQL Out node.
Finally please note I actually created those nodes couple of years ago ! Things got on the way and unfortunately I never published them so hopefully I could enhance them to make use of new additions in this space and you will make use of those in your projects. Contributions are much welcome .
If you have questions feel free to ask.
Cheers,
Neil