graphql-fields-list
Advanced tools
Comparing version 2.1.3 to 2.2.0
@@ -58,2 +58,7 @@ /*! | ||
/** | ||
* Flag which turns on/off whether to return the parent fields or not | ||
* @type {boolean} | ||
*/ | ||
keepParentField?: boolean; | ||
/** | ||
* Fields skip rule patterns. Usually used to ignore part of request field | ||
@@ -60,0 +65,0 @@ * subtree. For example if query looks like: |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fieldsProjection = exports.fieldsList = exports.fieldsMap = void 0; | ||
/** | ||
@@ -332,6 +333,9 @@ * Pre-compiled wildcard replacement regexp | ||
if (stack[0].tree[j]) { | ||
const nodeDottedName = toDotNotation(stack[0].node, j); | ||
stack.push({ | ||
node: toDotNotation(stack[0].node, j), | ||
node: nodeDottedName, | ||
tree: stack[0].tree[j], | ||
}); | ||
if (options === null || options === void 0 ? void 0 : options.keepParentField) | ||
map[nodeDottedName] = 1; | ||
continue; | ||
@@ -338,0 +342,0 @@ } |
{ | ||
"name": "graphql-fields-list", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"description": "Extracts and returns list of fields requested from graphql resolver info object", | ||
@@ -42,23 +42,23 @@ "scripts": { | ||
"devDependencies": { | ||
"@types/chai": "^4.2.11", | ||
"@types/chai": "^4.2.14", | ||
"@types/graphql": "^14.5.0", | ||
"@types/graphql-relay": "^0.4.11", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^13.9.1", | ||
"@types/sinon": "^7.5.2", | ||
"@types/uuid": "^7.0.0", | ||
"@types/graphql-relay": "^0.6.0", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.14.6", | ||
"@types/sinon": "^9.0.8", | ||
"@types/uuid": "^8.3.0", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.9", | ||
"graphql": "^14.6.0", | ||
"coveralls": "^3.1.0", | ||
"graphql": "^15.4.0", | ||
"graphql-relay": "^0.6.0", | ||
"marked": "^0.8.0", | ||
"mocha": "^7.1.0", | ||
"marked": "^1.2.3", | ||
"mocha": "^8.2.1", | ||
"npm-scripts-help": "^0.8.0", | ||
"nyc": "^15.0.0", | ||
"open": "^7.0.3", | ||
"sinon": "^9.0.1", | ||
"ts-node": "^8.6.2", | ||
"typedoc": "^0.17.0", | ||
"typescript": "^3.8.3", | ||
"uuid": "^7.0.2" | ||
"nyc": "^15.1.0", | ||
"open": "^7.3.0", | ||
"sinon": "^9.2.1", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.0.5", | ||
"uuid": "^8.3.1" | ||
}, | ||
@@ -65,0 +65,0 @@ "main": "index.js", |
@@ -294,2 +294,28 @@ # graphql-fields-list | ||
Projections also accepts keepParentField option, which should return the parents included in the object not only the leaves. | ||
```javascript | ||
const projection = fieldsProjection(info, { | ||
path: 'users', | ||
keepParentField: true, | ||
}); | ||
/* | ||
RESULT: | ||
projection = { | ||
'edges': 1, // parent node | ||
'edges.node': 1, // parent node | ||
'pageInfo': 1, // parent node | ||
'pageInfo.startCursor': 1, | ||
'pageInfo.endCursor': 1, | ||
'pageInfo.hasNextPage': 1, | ||
'edges.node.id': 1, | ||
'edges.node.firstName': 1, | ||
'edges.node.lastName': 1, | ||
'edges.node.phoneNumber': 1, | ||
'edges.node.email': 1, | ||
'edges.node.address': 1, | ||
} | ||
*/ | ||
``` | ||
Projections also accepts transform option, which should be a mapping object | ||
@@ -374,4 +400,22 @@ between projections paths: | ||
## Frequent Questions and Answers | ||
**Q1. Can we exclude `__typename` from fieldsList?** | ||
```typescript | ||
const some = fieldsList(info) | ||
// some output | ||
[ 'id', 'name', '__typename' ] | ||
``` | ||
**A1. Usually this problem occurs with using Apollo clients. | ||
Sure, you can overcome this with use of skip option:** | ||
```typescript | ||
const some = fieldsList(info, { skip: ['__*'] }) | ||
``` | ||
This is exactly the case, why skip option is created for. | ||
## License | ||
[ISC Licence](LICENSE) |
65412
7
1019
420