Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion utils/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
}

Expand Down
2 changes: 2 additions & 0 deletions utils/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down