@jumpn/utils-graphql
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -56,2 +56,39 @@ 'use strict'; | ||
var _this$1 = undefined; | ||
var operationTypeRe = /^\s*(query|mutation|subscription|\{)/; | ||
var getOperationTypeFromMatched = function (matched) { | ||
_newArrowCheck(this, _this$1); | ||
return matched === "{" ? "query" : matched; | ||
}.bind(undefined); | ||
/** | ||
* Returns the type of the given operation | ||
* | ||
* @example | ||
* | ||
* const operation = ` | ||
* subscription userSubscription($userId: ID!) { | ||
* user(userId: $userId) { | ||
* id | ||
* name | ||
* } | ||
* } | ||
* `; | ||
* | ||
* const operationType = getOperationType(operation); | ||
* | ||
* console.log(operationType); // "subscription" | ||
*/ | ||
var getOperationType = function (operation) { | ||
_newArrowCheck(this, _this$1); | ||
var result = operation.match(operationTypeRe); | ||
return result ? getOperationTypeFromMatched(result[1]) : undefined; | ||
}.bind(undefined); | ||
exports.errorsToString = errorsToString; | ||
exports.getOperationType = getOperationType; |
@@ -8,3 +8,3 @@ (function (global, factory) { | ||
function unwrapExports (x) { | ||
return x && x.__esModule ? x['default'] : x; | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
@@ -77,3 +77,40 @@ | ||
var _this$1 = undefined; | ||
var operationTypeRe = /^\s*(query|mutation|subscription|\{)/; | ||
var getOperationTypeFromMatched = function (matched) { | ||
_newArrowCheck(this, _this$1); | ||
return matched === "{" ? "query" : matched; | ||
}.bind(undefined); | ||
/** | ||
* Returns the type of the given operation | ||
* | ||
* @example | ||
* | ||
* const operation = ` | ||
* subscription userSubscription($userId: ID!) { | ||
* user(userId: $userId) { | ||
* id | ||
* name | ||
* } | ||
* } | ||
* `; | ||
* | ||
* const operationType = getOperationType(operation); | ||
* | ||
* console.log(operationType); // "subscription" | ||
*/ | ||
var getOperationType = function (operation) { | ||
_newArrowCheck(this, _this$1); | ||
var result = operation.match(operationTypeRe); | ||
return result ? getOperationTypeFromMatched(result[1]) : undefined; | ||
}.bind(undefined); | ||
exports.errorsToString = errorsToString; | ||
exports.getOperationType = getOperationType; | ||
@@ -80,0 +117,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -50,2 +50,38 @@ import _newArrowCheck from 'babel-runtime/helpers/newArrowCheck'; | ||
export { errorsToString }; | ||
var _this$1 = undefined; | ||
var operationTypeRe = /^\s*(query|mutation|subscription|\{)/; | ||
var getOperationTypeFromMatched = function (matched) { | ||
_newArrowCheck(this, _this$1); | ||
return matched === "{" ? "query" : matched; | ||
}.bind(undefined); | ||
/** | ||
* Returns the type of the given operation | ||
* | ||
* @example | ||
* | ||
* const operation = ` | ||
* subscription userSubscription($userId: ID!) { | ||
* user(userId: $userId) { | ||
* id | ||
* name | ||
* } | ||
* } | ||
* `; | ||
* | ||
* const operationType = getOperationType(operation); | ||
* | ||
* console.log(operationType); // "subscription" | ||
*/ | ||
var getOperationType = function (operation) { | ||
_newArrowCheck(this, _this$1); | ||
var result = operation.match(operationTypeRe); | ||
return result ? getOperationTypeFromMatched(result[1]) : undefined; | ||
}.bind(undefined); | ||
export { errorsToString, getOperationType }; |
{ | ||
"name": "@jumpn/utils-graphql", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "GraphQL utilities", | ||
@@ -19,3 +19,3 @@ "module": "dist/index.js", | ||
"precommit": "lint-staged", | ||
"commit": "git-cz", | ||
"commit": "commit", | ||
"commitmsg": "commitlint -e", | ||
@@ -25,7 +25,2 @@ "version": "yarn run build:index && yarn run build:readme && git add README.md src/index.js", | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -47,2 +42,8 @@ "*.js": [ | ||
"homepage": "https://github.com/jumpn/utils-graphql#readme", | ||
"keywords": [ | ||
"flow", | ||
"graphql", | ||
"utilities", | ||
"utils" | ||
], | ||
"dependencies": { | ||
@@ -52,36 +53,35 @@ "babel-runtime": "6.26.0" | ||
"devDependencies": { | ||
"@commitlint/cli": "3.2.0", | ||
"@commitlint/config-angular": "3.1.1", | ||
"@commitlint/cli": "4.2.1", | ||
"@commitlint/config-angular": "4.2.1", | ||
"@commitlint/prompt-cli": "4.2.1", | ||
"babel-cli": "6.26.0", | ||
"babel-core": "6.26.0", | ||
"babel-eslint": "8.0.0", | ||
"babel-eslint": "8.0.1", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babel-preset-env": "1.6.0", | ||
"babel-preset-env": "1.6.1", | ||
"babel-preset-flow": "6.23.0", | ||
"babel-preset-stage-0": "6.24.1", | ||
"commitizen": "2.9.6", | ||
"create-index": "2.2.0", | ||
"cz-conventional-changelog": "2.0.0", | ||
"documentation": "5.3.2", | ||
"eslint": "4.7.1", | ||
"eslint-config-airbnb-base": "12.0.0", | ||
"eslint-config-prettier": "2.5.0", | ||
"eslint-plugin-flowtype": "2.35.1", | ||
"eslint-plugin-flowtype-errors": "3.3.1", | ||
"eslint-plugin-import": "2.7.0", | ||
"documentation": "5.3.3", | ||
"eslint": "4.9.0", | ||
"eslint-config-airbnb-base": "12.1.0", | ||
"eslint-config-prettier": "2.6.0", | ||
"eslint-plugin-flowtype": "2.39.1", | ||
"eslint-plugin-flowtype-errors": "3.3.4", | ||
"eslint-plugin-import": "2.8.0", | ||
"eslint-plugin-prettier": "2.3.1", | ||
"flow-bin": "0.54.1", | ||
"flow-bin": "0.57.3", | ||
"flow-copy-source": "1.2.1", | ||
"flow-typed": "2.1.5", | ||
"flow-typed": "2.2.0", | ||
"husky": "0.14.3", | ||
"lint-staged": "4.2.1", | ||
"lint-staged": "4.3.0", | ||
"np": "2.16.0", | ||
"pascal-case": "2.0.1", | ||
"pkg-to-readme": "1.1.0", | ||
"prettier": "1.7.0", | ||
"prettier": "1.7.4", | ||
"rollup": "0.50.0", | ||
"rollup-plugin-babel": "3.0.2", | ||
"rollup-plugin-commonjs": "8.2.1", | ||
"rollup-plugin-commonjs": "8.2.4", | ||
"rollup-plugin-node-resolve": "3.0.0" | ||
} | ||
} |
@@ -18,2 +18,7 @@ # @jumpn/utils-graphql | ||
type GqlRequest<Variables: void | Object = void> = { | ||
operation: string, | ||
variables?: Variables | ||
}; | ||
type GqlResponse<Data> = { | ||
@@ -23,2 +28,4 @@ data?: Data, | ||
}; | ||
type GqlOperationType = "mutation" | "query" | "subscription"; | ||
``` | ||
@@ -56,4 +63,31 @@ | ||
### getOperationType | ||
Returns the type of the given operation | ||
**Parameters** | ||
- `operation` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
**Examples** | ||
```javascript | ||
const operation = ` | ||
subscription userSubscription($userId: ID!) { | ||
user(userId: $userId) { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
const operationType = getOperationType(operation); | ||
console.log(operationType); // "subscription" | ||
``` | ||
Returns **(void | GqlOperationType)** | ||
## License | ||
[MIT](LICENSE.txt) :copyright: **Jumpn Limited** / Mauro Titimoli (mauro@jumpn.com) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22013
32
20
376
91