From 9409eb26f55ea33f5b5ea4f92242c5b9dc59a8cf Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Thu, 27 Dec 2018 21:58:41 -0500 Subject: [PATCH] Support scalar and add coveralls --- .travis.yml | 2 + README.MD | 124 +++++--------- package-lock.json | 375 ++++++++++++++++++++++++++++++++++++++++- package.json | 10 +- test/mockBuilder.js | 3 + test/schema/schema.gql | 4 +- util/index.js | 9 + 7 files changed, 439 insertions(+), 88 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e31393..987ab57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ install: script: - npm run standard - npm test +after_success: + - npm run coveralls diff --git a/README.MD b/README.MD index 643756e..5fdfb6e 100644 --- a/README.MD +++ b/README.MD @@ -6,110 +6,72 @@
-Easy GraphQL mock is a node library used to create mocks of the schema. It will create -mocks of all the types that are on the GraphQL Schema, nested types are supported. +[![Coverage Status](https://coveralls.io/repos/github/EasyGraphQL/easygraphql-mock/badge.svg?branch=master)](https://coveralls.io/github/EasyGraphQL/easygraphql-mock?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/EasyGraphQL/easygraphql-mock.svg)](https://greenkeeper.io/) -## Installation +`easygraphql-mock` is a node library used to create mocks of a schema. +It will create mocks of all the types that are on the GraphQL Schema, including the nested types. -[![Greenkeeper badge](https://badges.greenkeeper.io/EasyGraphQL/easygraphql-mock.svg)](https://greenkeeper.io/) +## Installation -```bash +To install the package on your project just run on the root of your project +```shell $ npm install easygraphql-mock --save ``` -## Usage -To get started with the mocks, you might need to follow the next steps: - -### Basic -```js -const fs = require('fs') -const path = require('path') -const mocker = require('easygraphql-mock') -// Read the `graphql` file with the schema -const schemaCode = fs.readFileSync(path.join(__dirname, 'schema', 'schema.gql'), 'utf8') - -const mock = mocker(schemaCode) +## How to use it? -// All the types that are on the file are going to be created with a mock -console.log(mock.Me) -``` ++ Import [`easygraphql-mock`](https://github.com/EasyGraphQL/easygraphql-mock) package. ++ Read the schema. ++ Initialize the mock, and pass the schema as the first argument. + + If there are multiples schemas pass an array with the schemas an argument. + + **Note**: In order to use multiples schema files, the queries and mutations must be extended. ++ The second argument is optional and it is going to be your custom schema, in case you want to pass it. -### With definitions -You can set some values to the fields that you want on the schema. To do that, you might pass -an object to `easygqlmock` as a second argument. It should have the name of the type and the -field that you want to set. +*In case you have a custom scalar, set it on the second argument, if it's not set it will be {}* +### One schema file ```js +'use strict' + +const easygraphqlMock = require('easygraphql-mock') const fs = require('fs') const path = require('path') -const mocker = require('easygraphql-mock') -// Read the `graphql` file with the schema -const schemaCode = fs.readFileSync(path.join(__dirname, 'schema', 'schema.gql'), 'utf8') -const mock = mocker(schemaCode, { - Family: { - name: 'Super test 1', - ages: [10], - familyRelation: 'Mother', - familyRelationArr: ['Mother', 'Brother'] - } -}) +const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8') -// All the types that are on the file are going to be created with a mock -console.log(mock.Family) -console.log(mock.Family.name) // 'Super test 1' +const mockedSchema = easygraphqlMock(userSchema) ``` -## Use multiple Schema files -You can pass multiple schema files, just be shure that you extend the queries and mutations and -when you're creating the mock pass an array with the files: - - +### Multiples schemas files ```js +'use strict' + +const easygraphqlMock = require('easygraphql-mock') const fs = require('fs') const path = require('path') -const mocker = require('easygraphql-mock') -// Read the `graphql` file with the schema -const studentSchema = fs.readFileSync(path.join(__dirname, 'schema', 'student.gql'), 'utf8') -const schoolSchema = fs.readFileSync(path.join(__dirname, 'schema', 'school.gql'), 'utf8') -const mock = mocker([studentSchema, schoolSchema]) +const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8') +const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8') -// All the types that are on the file are going to be created with a mock -console.log(mock.Student) -console.log(mock.School) +const mockedSchema = easygraphqlMock([userSchema, familySchema]) ``` -## Result +### Custom schema +You can set some values to the fields that you want on the schema. To do that, you might pass an object as a second argument. +It must have the same name of the type and the field that you want to set. -If the `gql` schema has: -```graphql -enum FamilyRelation { - Father - Mother - Brother -} +```js +'use strict' -type Family { - name: String! - ages: [Int]! - user: User! - familyRelation: FamilyRelation! - familyRelationArr: [FamilyRelation]! -} +const easygraphqlMock = require('easygraphql-mock') +const fs = require('fs') +const path = require('path') -type User { - email: String! - username: String! - fullName: String! - phone: String! - family: Family! -} -``` +const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8') +const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8') -Run `mocker` -```js -const mock = mocker(schemaCode, { +const mockedSchema = easygraphqlMock([userSchema, familySchema], { + CustomScalarDate: '2018-10-10', Family: { name: 'Super test 1', ages: [10], @@ -117,14 +79,16 @@ const mock = mocker(schemaCode, { familyRelationArr: ['Mother', 'Brother'] } }) -console.log(mock.Family) ``` -And something like this will be the result for `mock.Family` +### Result +Here is the result of `mockedSchema.Family` + ```js { name: 'Super test 1', ages: [ 10 ], + createdAt: '2018-10-10', user: { email: 'ulalilid@herem.gl', username: 'tNfwN', @@ -138,7 +102,7 @@ And something like this will be the result for `mock.Family` username: tNfwN', fullName: 'Nathan Lewis', phone: '(231) 616-1744', - family: '...' + family: ... }, familyRelation: 'Mother', familyRelationArr: [ 'Mother', 'Brother' ] diff --git a/package-lock.json b/package-lock.json index a0868e7..5695d92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -198,12 +198,45 @@ "es-abstract": "1.12.0" } }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "dev": true, + "requires": { + "safer-buffer": "2.1.2" + } + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", + "dev": true + }, + "aws4": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", + "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", + "dev": true + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -263,6 +296,15 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "dev": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -309,6 +351,12 @@ "integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=", "dev": true }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", + "dev": true + }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -393,6 +441,15 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, + "combined-stream": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", + "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", + "dev": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, "commander": { "version": "2.15.1", "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", @@ -411,6 +468,12 @@ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", "dev": true }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, "cosmiconfig": { "version": "5.0.7", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.0.7.tgz", @@ -423,6 +486,28 @@ "parse-json": "4.0.0" } }, + "coveralls": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.2.tgz", + "integrity": "sha512-Tv0LKe/MkBOilH2v7WBiTBdudg2ChfGbdXafc/s330djpF3zKOmuehTeRwjXWc7pzfj9FrDUTA7tEx6Div8NFw==", + "dev": true, + "requires": { + "growl": "1.10.5", + "js-yaml": "3.12.0", + "lcov-parse": "0.0.10", + "log-driver": "1.2.7", + "minimist": "1.2.0", + "request": "2.88.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -436,6 +521,15 @@ "which": "1.3.1" } }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dev": true, + "requires": { + "assert-plus": "1.0.0" + } + }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", @@ -497,6 +591,12 @@ } } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -513,14 +613,24 @@ } }, "easygraphql-parser": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/easygraphql-parser/-/easygraphql-parser-0.0.3.tgz", - "integrity": "sha512-k2QQFgR/XZJb3wAP4wp/CWKoa6ncSofO8MFz9fw8dQYETygBNeVU8/gHQeOn9zTDA4S3Eagu7cd3bPL+zwQhLg==", + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/easygraphql-parser/-/easygraphql-parser-0.0.5.tgz", + "integrity": "sha512-039Mpk6HG2PH3rCsT/rPiQcZPVq4VixK5Yyyae7KDx5+aV425z3qjG6suJs3ipqFIGNMOCUXK2zR5x/I0ALv+w==", "requires": { "graphql": "14.0.2", "lodash.mergewith": "4.6.1" } }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "dev": true, + "requires": { + "jsbn": "0.1.1", + "safer-buffer": "2.1.2" + } + }, "end-of-stream": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", @@ -869,6 +979,12 @@ "strip-eof": "1.0.0" } }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true + }, "external-editor": { "version": "2.2.0", "resolved": "http://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", @@ -880,6 +996,12 @@ "tmp": "0.0.33" } }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", + "dev": true + }, "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", @@ -944,6 +1066,23 @@ "write": "0.2.1" } }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", + "dev": true + }, + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "dev": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.7", + "mime-types": "2.1.21" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -983,6 +1122,15 @@ "pump": "3.0.0" } }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dev": true, + "requires": { + "assert-plus": "1.0.0" + } + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -1023,6 +1171,22 @@ "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", + "dev": true + }, + "har-validator": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", + "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", + "dev": true, + "requires": { + "ajv": "6.6.2", + "har-schema": "2.0.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -1065,6 +1229,17 @@ "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "dev": true, + "requires": { + "assert-plus": "1.0.0", + "jsprim": "1.4.1", + "sshpk": "1.16.0" + } + }, "husky": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/husky/-/husky-1.2.1.tgz", @@ -1235,6 +1410,12 @@ "has-symbols": "1.0.0" } }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", + "dev": true + }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -1247,6 +1428,12 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", + "dev": true + }, "istanbul-lib-coverage": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz", @@ -1289,6 +1476,12 @@ "esprima": "4.0.1" } }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "dev": true + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -1301,6 +1494,12 @@ "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "dev": true }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "dev": true + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -1313,6 +1512,24 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", + "dev": true + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "dev": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, "jsx-ast-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", @@ -1322,6 +1539,12 @@ "array-includes": "3.0.3" } }, + "lcov-parse": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-0.0.10.tgz", + "integrity": "sha1-GwuP+ayceIklBYK3C3ExXZ2m2aM=", + "dev": true + }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -1382,6 +1605,12 @@ "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz", "integrity": "sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==" }, + "log-driver": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", + "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", + "dev": true + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -1391,6 +1620,21 @@ "js-tokens": "4.0.0" } }, + "mime-db": { + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz", + "integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg==", + "dev": true + }, + "mime-types": { + "version": "2.1.21", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz", + "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==", + "dev": true, + "requires": { + "mime-db": "1.37.0" + } + }, "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", @@ -2624,6 +2868,12 @@ } } }, + "oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", + "dev": true + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2767,6 +3017,12 @@ "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", "dev": true }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", + "dev": true + }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", @@ -2912,6 +3168,12 @@ "object-assign": "4.1.1" } }, + "psl": { + "version": "1.1.31", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", + "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==", + "dev": true + }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -2928,6 +3190,12 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "dev": true + }, "read-pkg": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-4.0.1.tgz", @@ -3011,6 +3279,34 @@ "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "request": { + "version": "2.88.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", + "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", + "dev": true, + "requires": { + "aws-sign2": "0.7.0", + "aws4": "1.8.0", + "caseless": "0.12.0", + "combined-stream": "1.0.7", + "extend": "3.0.2", + "forever-agent": "0.6.1", + "form-data": "2.3.3", + "har-validator": "5.1.3", + "http-signature": "1.2.0", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.21", + "oauth-sign": "0.9.0", + "performance-now": "2.1.0", + "qs": "6.5.2", + "safe-buffer": "5.1.2", + "tough-cookie": "2.4.3", + "tunnel-agent": "0.6.0", + "uuid": "3.3.2" + } + }, "require-uncached": { "version": "1.0.3", "resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", @@ -3108,6 +3404,12 @@ "symbol-observable": "1.0.1" } }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -3206,6 +3508,23 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "sshpk": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.0.tgz", + "integrity": "sha512-Zhev35/y7hRMcID/upReIvRse+I9SVhyVre/KTJSJQWMz3C3+G+HpO7m1wK/yckEtujKZ7dS4hkVxAnmHaIGVQ==", + "dev": true, + "requires": { + "asn1": "0.2.4", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.2", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.2", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "safer-buffer": "2.1.2", + "tweetnacl": "0.14.5" + } + }, "standard": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/standard/-/standard-12.0.1.tgz", @@ -3344,12 +3663,45 @@ "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true }, + "tough-cookie": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", + "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", + "dev": true, + "requires": { + "psl": "1.1.31", + "punycode": "1.4.1" + }, + "dependencies": { + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", + "dev": true + } + } + }, "trim-right": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "dev": true, + "requires": { + "safe-buffer": "5.1.2" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "dev": true + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -3380,6 +3732,12 @@ "punycode": "2.1.1" } }, + "uuid": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", + "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -3390,6 +3748,17 @@ "spdx-expression-parse": "3.0.0" } }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "dev": true, + "requires": { + "assert-plus": "1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "1.3.0" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 11f49b5..7c64e98 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "test": "nyc --check-coverage --lines 90 mocha", "standard": "standard", - "standard-fix": "standard --fix" + "standard-fix": "standard --fix", + "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls" }, "husky": { "hooks": { @@ -40,13 +41,14 @@ "license": "MIT", "dependencies": { "chance": "^1.0.16", - "easygraphql-parser": "^0.0.3" + "easygraphql-parser": "^0.0.5" }, "devDependencies": { "chai": "^4.1.2", + "coveralls": "^3.0.2", + "husky": "^1.1.3", "mocha": "^5.2.0", "nyc": "^13.0.1", - "standard": "^12.0.1", - "husky": "^1.1.3" + "standard": "^12.0.1" } } diff --git a/test/mockBuilder.js b/test/mockBuilder.js index 6913df0..2081810 100644 --- a/test/mockBuilder.js +++ b/test/mockBuilder.js @@ -16,6 +16,7 @@ describe('Create a mock of GraphQL Schema', () => { before(() => { mock = easygqlmock(schemaCode, { + DateTime: '2018-10-10', Me: { id: '123', fullName: 'Hello World!', @@ -62,6 +63,8 @@ describe('Create a mock of GraphQL Schema', () => { expect(mock.Me.users[0].family.name).to.be.a('string') expect(['Father', 'Mother', 'Brother']).to.include(mock.Me.users[0].family.familyRelation) expect(mock.Me.verified).to.be.a('boolean') + expect(mock.Me.createdAt).to.be.exist + expect(mock.Me.createdAt).to.be.eq('2018-10-10') }) }) diff --git a/test/schema/schema.gql b/test/schema/schema.gql index 8a427be..c4a19ff 100644 --- a/test/schema/schema.gql +++ b/test/schema/schema.gql @@ -1,4 +1,5 @@ -scalar JSON +scalar DateTime + enum FamilyRelation { Father Mother @@ -23,6 +24,7 @@ type Me { apiKey: String! users: [User]! verified: Boolean! + createdAt: DateTime! } type User { diff --git a/util/index.js b/util/index.js index 7db6418..f7cfcb5 100644 --- a/util/index.js +++ b/util/index.js @@ -46,6 +46,15 @@ const mockedField = (type, customMock, schema) => { const memoizedField = memoize(mockedField) function createData (field, schemaName, customMock = {}, schema) { + // Validate if the field is a scalar, if it's validate if there is a custom + // value to assign to it. + if ( + schema[field.type] && + schema[field.type].type === 'ScalarTypeDefinition' && + customMock[field.type] + ) { + return customMock[field.type] + } // Validate if the schema name exists on the custom mock and also check if the // actual field exists, in case that it exists, make the validations to set it // as result.