@platformatic/sql-graphql
Advanced tools
Comparing version 0.45.1 to 0.46.1
20
index.js
@@ -8,2 +8,3 @@ 'use strict' | ||
const { mercuriusFederationPlugin } = require('@mercuriusjs/federation') | ||
const { findNearestString } = require('@platformatic/utils') | ||
const establishRelations = require('./lib/relationship') | ||
@@ -41,8 +42,23 @@ const setupSubscriptions = require('./lib/subscriptions') | ||
} else { | ||
const entitiesNames = Object.values(mapper.entities) | ||
.map(entity => entity.singularName) | ||
for (const ignoredEntity of Object.keys(ignore)) { | ||
if (!entitiesNames.includes(ignoredEntity)) { | ||
const nearestEntity = findNearestString(entitiesNames, ignoredEntity) | ||
let warningMessage = `Ignored graphql entity "${ignoredEntity}" not found.` | ||
/* istanbul ignore next */ | ||
if (nearestEntity) { | ||
warningMessage += ` Did you mean "${nearestEntity}"?` | ||
} | ||
app.log.warn(warningMessage) | ||
} | ||
} | ||
for (const entity of Object.values(mapper.entities)) { | ||
if (ignore[entity.pluralName] === true) { | ||
if (ignore[entity.singularName] === true) { | ||
continue | ||
} | ||
relations.push(...entity.relations) | ||
const meta = constructGraph(app, entity, graphOpts, ignore[entity.pluralName] || {}) | ||
const meta = constructGraph(app, entity, graphOpts, ignore[entity.singularName] || {}) | ||
metaMap.set(entity, meta) | ||
@@ -49,0 +65,0 @@ } |
@@ -5,2 +5,3 @@ 'use strict' | ||
const camelcase = require('camelcase') | ||
const { findNearestString } = require('@platformatic/utils') | ||
const { | ||
@@ -41,2 +42,15 @@ sqlTypeToGraphQL, | ||
const entityFieldsNames = Object.values(entity.fields) | ||
.map(field => field.camelcase) | ||
for (const ignoredField of Object.keys(ignore)) { | ||
if (!entityFieldsNames.includes(ignoredField)) { | ||
const nearestField = findNearestString(entityFieldsNames, ignoredField) | ||
app.log.warn( | ||
`Ignored graphql field "${ignoredField}" not found in entity "${entity.singularName}".` + | ||
` Did you mean "${nearestField}"?` | ||
) | ||
} | ||
} | ||
const fields = {} | ||
@@ -43,0 +57,0 @@ |
{ | ||
"name": "@platformatic/sql-graphql", | ||
"version": "0.45.1", | ||
"version": "0.46.1", | ||
"description": "Map SQL dbs to GraphQL", | ||
@@ -25,4 +25,4 @@ "main": "index.js", | ||
"ws": "^8.13.0", | ||
"@platformatic/sql-events": "0.45.1", | ||
"@platformatic/sql-mapper": "0.45.1" | ||
"@platformatic/sql-events": "0.46.1", | ||
"@platformatic/sql-mapper": "0.46.1" | ||
}, | ||
@@ -38,3 +38,4 @@ "dependencies": { | ||
"inflected": "^2.1.0", | ||
"mercurius": "^13.0.0" | ||
"mercurius": "^13.0.0", | ||
"@platformatic/utils": "0.46.1" | ||
}, | ||
@@ -41,0 +42,0 @@ "tsd": { |
@@ -132,3 +132,3 @@ 'use strict' | ||
ignore: { | ||
categories: true | ||
category: true | ||
} | ||
@@ -162,2 +162,42 @@ }) | ||
test('show a warning if there is no ignored entity', async ({ plan, pass, teardown }) => { | ||
plan(2) | ||
const app = fastify({ | ||
logger: { | ||
info () {}, | ||
debug () {}, | ||
trace () {}, | ||
fatal () {}, | ||
error () {}, | ||
child () { | ||
return this | ||
}, | ||
warn (msg) { | ||
if (msg === 'Ignored graphql entity "missingEntityPages" not found. Did you mean "page"?') { | ||
pass('warning message is shown') | ||
} | ||
} | ||
} | ||
}) | ||
app.register(sqlMapper, { | ||
...connInfo, | ||
async onDatabaseLoad (db, sql) { | ||
pass('onDatabaseLoad called') | ||
await clear(db, sql) | ||
await createBasicPages(db, sql) | ||
} | ||
}) | ||
app.register(sqlGraphQL, { | ||
ignore: { | ||
missingEntityPages: true | ||
} | ||
}) | ||
teardown(app.close.bind(app)) | ||
await app.ready() | ||
}) | ||
test('ignore a column via sql-graphql option', async ({ pass, teardown, equal }) => { | ||
@@ -176,3 +216,3 @@ const app = fastify() | ||
ignore: { | ||
categories: { | ||
category: { | ||
name: true | ||
@@ -211,1 +251,43 @@ } | ||
}) | ||
test('show a warning if there is no ignored entity field', async ({ plan, pass, teardown }) => { | ||
plan(2) | ||
const app = fastify({ | ||
logger: { | ||
info () {}, | ||
debug () {}, | ||
trace () {}, | ||
fatal () {}, | ||
error () {}, | ||
child () { | ||
return this | ||
}, | ||
warn (msg) { | ||
if (msg === 'Ignored graphql field "missingFieldName" not found in entity "category". Did you mean "name"?') { | ||
pass('warning message is shown') | ||
} | ||
} | ||
} | ||
}) | ||
app.register(sqlMapper, { | ||
...connInfo, | ||
async onDatabaseLoad (db, sql) { | ||
pass('onDatabaseLoad called') | ||
await clear(db, sql) | ||
await createBasicPages(db, sql) | ||
} | ||
}) | ||
app.register(sqlGraphQL, { | ||
ignore: { | ||
category: { | ||
missingFieldName: true | ||
} | ||
} | ||
}) | ||
teardown(app.close.bind(app)) | ||
await app.ready() | ||
}) |
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
283688
11137
10
+ Added@platformatic/utils@0.46.1
+ Added@fastify/deepmerge@1.3.0(transitive)
+ Added@platformatic/utils@0.46.1(transitive)
+ Addedleven@3.1.0(transitive)
+ Addedminimatch@8.0.4(transitive)