@@ -12,46 +12,51 @@ Lightweight driven query language
1212
1313Here's the first example to get you started. [ Try it here] ( https://codepen.io/syarul/pen/xxmLMVP ) —no build step required!
1414
15- ## Comparison to graphQL
15+ ## Features
1616
17- | Feature | GraphQL | reQurse |
18- | --------------- | --------------------------------------------------------- | ----------------------------------------------------- |
19- | Query Syntax | ✅ Declarative queries as strings (SDL) | ✅ JSON object-based queries |
20- | Schema & Typing | ✅ Strongly typed schemas | ❌ No type enforcement (support GraphQL schema) |
21- | Resolvers | ✅ Defined server-side logic for each field | ✅ ` methods ` functions resolve keys |
22- | API Federation | ✅ Built-in with tools like Apollo Federation | ✅ Can compose multiple ` rq() ` into one federated API |
23- | Use Cases | ✅ Full APIs, strongly validated, efficient data fetching | ✅ Full APIs, Lightweight, data orchestration |
24- | Runtime | ✅ Client-server over HTTP | ✅ Client-server over HTTP/In-process library calls |
25- | Complexity | ❌ Requires schema + resolvers + server setup | ✅ Very light; no server setup |
17+ | Feature | reQurse |
18+ | --------------- | ----------------------------------------------------------------- |
19+ | Query Syntax | ✅ JSON object-based queries |
20+ | Schema & Typing | ❌ No type enforcement (support GraphQL schema) |
21+ | Resolvers | ✅ ` methods ` functions resolve keys |
22+ | API Federation | ✅ Can compose multiple instance of ` rq() ` into one federated API |
23+ | Caching | ✅ Implemented (pass in options) |
24+ | Use Cases | ✅ Full APIs, Lightweight, data orchestration |
25+ | Runtime | ✅ Client-server over HTTP/In-process library calls |
26+ | Complexity | ✅ Very light; no server setup |
2627
27- As example using the [ RandomDie] ( https://www.graphql-js.org/docs/object-types/ ) sample
28+ As direct comparison with graphQL using the [ RandomDie] ( https://www.graphql-js.org/docs/object-types/ ) sample
2829
2930``` js
3031// graphQL
3132const RandomDie = new GraphQLObjectType ({
3233 name: " RandomDie" ,
33- fields: {
34- numSides: {
35- type: new GraphQLNonNull (GraphQLInt),
36- resolve : (die ) => die .numSides ,
37- },
38- rollOnce: {
39- type: new GraphQLNonNull (GraphQLInt),
40- resolve : (die ) => 1 + Math .floor (Math .random () * die .numSides ),
41- },
42- roll: {
43- type: new GraphQLList (GraphQLInt),
44- args: {
45- numRolls: { type: new GraphQLNonNull (GraphQLInt) },
34+ fields : () => {
35+ const fields = {
36+ numSides: {
37+ type: new GraphQLNonNull (GraphQLInt),
38+ resolve : (die ) => die .numSides ,
4639 },
47- resolve : (die , { numRolls }) => {
48- const output = [];
49- for (let i = 0 ; i < numRolls; i++ ) {
50- output .push (1 + Math .floor (Math .random () * die .numSides ));
51- }
52- return output;
40+ rollOnce: {
41+ type: new GraphQLNonNull (GraphQLInt),
42+ resolve : (die ) => 1 + Math .floor (Math .random () * die .numSides ),
5343 },
54- },
44+ roll: {
45+ type: new GraphQLList (GraphQLInt),
46+ args: {
47+ numRolls: { type: new GraphQLNonNull (GraphQLInt) },
48+ },
49+ resolve : (die , { numRolls }, ctx , info ) => {
50+ const rollOnceResolver = fields .rollOnce .resolve ;
51+ const output = [];
52+ for (let i = 0 ; i < numRolls; i++ ) {
53+ output .push (rollOnceResolver (die, {}, ctx, info));
54+ }
55+ return output;
56+ },
57+ },
58+ };
59+ return fields;
5560 },
5661});
5762
@@ -117,7 +122,7 @@ class RandomDie extends RqExtender {
117122 for (let i = 0 ; i < numRolls; i++ ) {
118123 // reuse rollOnce here
119124 // context is using rq context
120- // {
125+ // {
121126 // query, // combine queryResult
122127 // computes, // computed fields
123128 // }
@@ -184,12 +189,16 @@ A basic usage of reQurse.
184189``` javascript
185190import rq from " requrse" ;
186191
187- rq (query, { methods, config });
192+ rq (query, { methods, config, dataUrl, rootKey, cache, cacheDir });
188193```
189194
190195- ** query** : _ (object)_ ** _ required_ ** JSON like query.
191196- ** methods** : _ (object)_ ** _ required_ ** define methods/computed fields that exist in the query.
192197- ** config** : _ (object)_ ** _ optional_ ** extend and added parameterize control over methods.
198+ - ** dataUrl** : _ (string)_ ** _ optional_ ** resolve result to data url path.
199+ - ** rootKey** : _ (string)_ ** _ optional_ ** graphQL root key if using graphQL query, default to 'data' if not given.
200+ - ** cache** : _ (number)_ ** _ optional_ ** cache result in second(s).
201+ - ** cacheDir** : _ (string)_ ** _ optional_ ** custom caching directory default is '.tmp'.
193202
194203``` js
195204await rq (
0 commit comments