diff --git a/package-lock.json b/package-lock.json index 41d1640..498c829 100644 --- a/package-lock.json +++ b/package-lock.json @@ -613,9 +613,9 @@ } }, "easygraphql-mock": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/easygraphql-mock/-/easygraphql-mock-0.1.6.tgz", - "integrity": "sha512-mS3fSCVCfIkzLTBEuGyJhQ/frHp3AO7UmXgOY9IyfDJQmI0ZZOdOUAEcnM9Tg3vGiExPuxE79N4Zlh4lf8o0QA==", + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/easygraphql-mock/-/easygraphql-mock-0.1.7.tgz", + "integrity": "sha512-Ha3ZizXjIhgTDa+utRHJ++xHewj0VxRL6ZG+1y4x7P1HnlceapdI6ZIjOB6O0fHoY7NLGVlfJneSRaPvfKvU+g==", "requires": { "chance": "1.0.18", "easygraphql-parser": "0.0.5" diff --git a/package.json b/package.json index 158f476..067549b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "license": "MIT", "dependencies": { - "easygraphql-mock": "^0.1.6", + "easygraphql-mock": "^0.1.7", "easygraphql-parser": "^0.0.5", "graphql-tag": "^2.9.2", "lodash.isempty": "^4.4.0", diff --git a/utils/fixture.js b/utils/fixture.js index c62dcbd..0e4d800 100644 --- a/utils/fixture.js +++ b/utils/fixture.js @@ -28,13 +28,22 @@ function handleObjectFixture (mock, fixture) { throw new Error(`${val} is not called on the query, and it's on the fixture.`) } + // If it is a scalar, it should be an empty object instead of the __typename + if (isObject(mock[val]) && Object.keys(mock[val]).length === 1 && mock[val].__typename) { + mock[val] = {} + } + if (Array.isArray(mock[val]) && !Array.isArray(fixture[val])) { throw new Error(`${val} is not an array and it should be one.`) } // if the mock[val] is empty it is because it's a custom scalar, in this case // it should not be validated - if (mock[val] !== null && typeof mock[val] !== typeof fixture[val] && !isEmpty(mock[val])) { + if ( + mock[val] !== null && + typeof mock[val] !== typeof fixture[val] && + !isEmpty(mock[val]) + ) { throw new Error(`${val} is not the same type as the document.`) } diff --git a/utils/validator.js b/utils/validator.js index d113430..87a4f22 100644 --- a/utils/validator.js +++ b/utils/validator.js @@ -355,6 +355,8 @@ function getResult (query, mock, schema, schemaType, type) { } function validateSelectedFields (field, selectedSchema, schema, name, type) { + if (field.name === '__typename') return + const schemaFields = selectedSchema.fields.filter(schemaField => schemaField.name === field.name)[0] if (!schemaFields) { throw new Error(`${type} ${name}: The selected field ${field.name} doesn't exists`)