Example apps using feathers-plus/graphql
- Make sure you have NodeJS and npm installed.
- Change the directory to the example you want to run, e.g.
cd graphql-examples/js-nedb-services
- Install your dependencies
npm install
- Start the app
npm start
Point your browser at localhost:3030
and you will see this test harness:
The client will authenticate with the server before enabling the Run query
button.
You can run any of the 10 provided queries.
The query appears in the editable window on top.
The result (or error message) appears in the bottom window after you click Run query
.
You can modify any of those queries before running them.
The keywords allowed in some of the resolvers are Feathers service-like:
- key: The same as Feathers
id
, numeric or string. - query: The same as Feathers
params.query
. - params: The same as Feathers
params
.
$
is a reserved character in GraphQL, so Feathers props such as $sort
and $in
will result in GraphQL errors.
You can instead use a double underscore __
where ever you would use a $
with Feathers.
This app can use either an NeDB or SQLite database, both of which reside in ./data
.
Both databases have the same structure:
and contain the same data:
This repo contains several example FeathersJS applications using GraphQL Query via the feathers-plus/graphql adapter.
The examples all use the same data set, and the same frontend client for testing. Each example is available in both JavaScript and TypeScript.
The examples differ in the database being used and in how the Query is resolved. We've chosen representative databases which require no installation.
Two examples use the NeDB database. They differ in how they resolve the GraphQL query:
- Feathers services only are used in examples js-nedb-service and ts-nedb-services.
- Feathers services with batch-loaders are used in examples js-nedb-batchloaders and ts-nedb-batchloaders.
These examples will work without any GraphQL related changes for MongoDB and Mongoose.
The Sequelize ORM supports multiple SQL databases. Three examples use it with the SQLite database. They also differ in how they resolve the GraphQL query:
- Feathers services only are used in examples js-sequelize-service and ts-sequelize-services.
- Feathers services with batch-loaders are used in examples js-sequelize-batchloaders and ts-sequelize-batchloaders.
- Raw SQL statements are generated in examples js-sequelize-sql and ts-sequelize-sql.
These examples will work without any GraphQL related changes for PostgreSQL, MySQL, and MSSQL. They would also work with the Knex ORM.
The 5 examples (both in .js and .ts flavors) differ in how they implement their GraphQL resolvers.
When FeathersJS services alone are used, each resolver makes its own service call. This is the simplest way to set up resolvers, but it also generates the most service calls.
A cache is automatically created for each resolver when FeathersJS services are used with batch-loaders. The same record is only read once.
The resolver requests are also batched. Just one service call is made for several resolver calls.
Batch-loaders may also be shared among resolvers. The same batch-loader, for example, may be used by resolvers needing the Users table. This further reduces the number of service calls as one cache is shared, and service calls for different resolvers may be satisfied together in one service call.
It is more complex to set up batch-loader resolvers than ones using just FeathersJS services, batch-loaders may typically reduce the number of service calls by a factor of 10, e.g. 2 calls instead of 20.
Join-monster is a query planner between GraphQL and SQL for the Node.js graphql-js reference implementation. It's a function that takes a GraphQL query and dynamically translates GraphQL to SQL for efficient, batched data retrieval before resolution. It fetches only the data you need - nothing more, nothing less.
Setting up resolvers for join-monster
is more complex than the previous 2 methods.
The results will be significantly faster than using FeathersJS services alone.
The results may be usefully faster than using batch-loaders,
depending on the Query and on the data set,
This app can use either an NeDB or SQLite database, both of which reside in ./data
.
Both databases have the same structure:
and contain the same data:
Copyright (c) 2018
Licensed under the MIT license.