-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hack the V5 inflectors for naming consistency
- Loading branch information
Showing
6 changed files
with
404 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
diff --git a/node_modules/graphile-build/dist/newWithHooks/index.js b/node_modules/graphile-build/dist/newWithHooks/index.js | ||
index dc0d978..46e0a9c 100644 | ||
--- a/node_modules/graphile-build/dist/newWithHooks/index.js | ||
+++ b/node_modules/graphile-build/dist/newWithHooks/index.js | ||
@@ -5,6 +5,7 @@ const grafast_1 = require("grafast"); | ||
const graphql_1 = require("grafast/graphql"); | ||
const util_1 = require("util"); | ||
const utils_js_1 = require("../utils.js"); | ||
+const { assertName } = require("graphql"); | ||
const isString = (str) => typeof str === "string"; | ||
const knownTypes = [ | ||
graphql_1.GraphQLSchema, | ||
@@ -81,6 +82,11 @@ function makeNewWithHooks({ builder }) { | ||
const processedFields = []; | ||
const fieldWithHooks = (fieldScope, fieldSpec) => { | ||
const { fieldName } = fieldScope; | ||
+ try { | ||
+ assertName(fieldName) | ||
+ } catch (e) { | ||
+ throw new Error(`Attempted to add field ${JSON.stringify(fieldName)} to object type ${Self.name}, but that's not a valid name: ${e.message}`) | ||
+ } | ||
build.extend(fieldScope, scope, "Adding the object type scope to the field's scope"); | ||
if (!isString(fieldName)) { | ||
throw new Error("It looks like you forgot to pass the fieldName to `fieldWithHooks`, we're sorry this is current necessary."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
diff --git a/node_modules/graphile-build-pg/dist/plugins/PgAttributesPlugin.js b/node_modules/graphile-build-pg/dist/plugins/PgAttributesPlugin.js | ||
index 88c6973..e523ea1 100644 | ||
--- a/node_modules/graphile-build-pg/dist/plugins/PgAttributesPlugin.js | ||
+++ b/node_modules/graphile-build-pg/dist/plugins/PgAttributesPlugin.js | ||
@@ -120,21 +120,25 @@ exports.PgAttributesPlugin = { | ||
add: { | ||
_attributeName(options, { attributeName, codec }) { | ||
const attribute = codec.attributes[attributeName]; | ||
- return this.coerceToGraphQLName(attribute.extensions?.tags?.name || attributeName); | ||
+ const name = attribute.extensions?.tags?.name || attributeName | ||
+ // Avoid conflict with 'id' field used for Relay. | ||
+ const nonconflictName = | ||
+ name === "id" && !codec.isAnonymous | ||
+ ? "row_id" | ||
+ : name; | ||
+ return this.coerceToGraphQLName( | ||
+ nonconflictName | ||
+ ); | ||
}, | ||
_joinAttributeNames(options, codec, names) { | ||
return names | ||
.map((attributeName) => { | ||
- return this.attribute({ attributeName, codec }); | ||
+ return this._attributeName({ attributeName, codec }); | ||
}) | ||
.join("-and-"); | ||
}, | ||
attribute(options, details) { | ||
- const attributeFieldName = this.camelCase(this._attributeName(details)); | ||
- // Avoid conflict with 'id' field used for Relay. | ||
- return attributeFieldName === "id" && !details.codec.isAnonymous | ||
- ? "rowId" | ||
- : attributeFieldName; | ||
+ return this.camelCase(this._attributeName(details)); | ||
}, | ||
}, | ||
}, | ||
diff --git a/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.d.ts b/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.d.ts | ||
index 04ed8f0..2620bb0 100644 | ||
--- a/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.d.ts | ||
+++ b/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.d.ts | ||
@@ -45,6 +45,8 @@ declare global { | ||
}): string; | ||
singleRelation(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
singleRelationBackwards(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
+ _singleRelationRaw(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
+ _singleRelationBackwardsRaw(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
_manyRelation(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
manyRelationConnection(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
manyRelationList(this: Inflection, details: PgRelationsPluginRelationDetails): string; | ||
diff --git a/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.js b/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.js | ||
index 117fc39..85d19fc 100644 | ||
--- a/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.js | ||
+++ b/node_modules/graphile-build-pg/dist/plugins/PgRelationsPlugin.js | ||
@@ -42,7 +42,7 @@ exports.PgRelationsPlugin = { | ||
const attributeNames = attributes.map((col) => col.attname); | ||
return this.camelCase(`${isUnique ? remoteName : this.pluralize(remoteName)}-by-${isReferencee ? "their" : "my"}-${attributeNames.join("-and-")}`); | ||
}, | ||
- singleRelation(options, details) { | ||
+ _singleRelationRaw(options, details) { | ||
const { registry, codec, relationName } = details; | ||
const relation = registry.pgRelations[codec.name]?.[relationName]; | ||
//const codec = relation.remoteResource.codec; | ||
@@ -52,9 +52,12 @@ exports.PgRelationsPlugin = { | ||
// E.g. posts(author_id) references users(id) | ||
const remoteType = this.tableType(relation.remoteResource.codec); | ||
const localAttributes = relation.localAttributes; | ||
- return this.camelCase(`${remoteType}-by-${this._joinAttributeNames(codec, localAttributes)}`); | ||
+ return (`${remoteType}-by-${this._joinAttributeNames(codec, localAttributes)}`); | ||
}, | ||
- singleRelationBackwards(options, details) { | ||
+ singleRelation(options, details) { | ||
+ return this.camelCase(this._singleRelationRaw(details)) | ||
+ }, | ||
+ _singleRelationBackwardsRaw(options, details) { | ||
const { registry, codec, relationName } = details; | ||
const relation = registry.pgRelations[codec.name]?.[relationName]; | ||
if (typeof relation.extensions?.tags.foreignSingleFieldName === "string") { | ||
@@ -66,9 +69,12 @@ exports.PgRelationsPlugin = { | ||
// E.g. posts(author_id) references users(id) | ||
const remoteType = this.tableType(relation.remoteResource.codec); | ||
const remoteAttributes = relation.remoteAttributes; | ||
- return this.camelCase(`${remoteType}-by-${this._joinAttributeNames(relation.remoteResource.codec, remoteAttributes)}`); | ||
+ return (`${remoteType}-by-${this._joinAttributeNames(relation.remoteResource.codec, remoteAttributes)}`); | ||
}, | ||
- _manyRelation(options, details) { | ||
+ singleRelationBackwards(options, details) { | ||
+ return this.camelCase(this._singleRelationBackwardsRaw(details)) | ||
+ }, | ||
+ _manyRelationRaw(options, details) { | ||
const { registry, codec, relationName } = details; | ||
const relation = registry.pgRelations[codec.name]?.[relationName]; | ||
const baseOverride = relation.extensions?.tags.foreignFieldName; | ||
@@ -78,7 +84,10 @@ exports.PgRelationsPlugin = { | ||
// E.g. users(id) references posts(author_id) | ||
const remoteType = this.tableType(relation.remoteResource.codec); | ||
const remoteAttributes = relation.remoteAttributes; | ||
- return this.camelCase(`${this.pluralize(remoteType)}-by-${this._joinAttributeNames(relation.remoteResource.codec, remoteAttributes)}`); | ||
+ return (`${this.pluralize(remoteType)}-by-${this._joinAttributeNames(relation.remoteResource.codec, remoteAttributes)}`); | ||
+ }, | ||
+ _manyRelation(options, details) { | ||
+ return this.camelCase(this._manyRelationRaw(details)) | ||
}, | ||
manyRelationConnection(options, details) { | ||
const { registry, codec, relationName } = details; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
diff --git a/node_modules/postgraphile/dist/presets/v4.js b/node_modules/postgraphile/dist/presets/v4.js | ||
index a8d69be..44ba8cb 100644 | ||
--- a/node_modules/postgraphile/dist/presets/v4.js | ||
+++ b/node_modules/postgraphile/dist/presets/v4.js | ||
@@ -58,9 +58,10 @@ const makeV4Plugin = (options) => { | ||
? null | ||
: { | ||
// Don't rename 'id' to 'rowId' | ||
- attribute(previous, options, details) { | ||
- const attributeFieldName = this.camelCase(this._attributeName(details)); | ||
- return attributeFieldName; | ||
+ _attributeName(previous, options, {attributeName, codec}) { | ||
+ const attribute = codec.attributes[attributeName]; | ||
+ const name = attribute.extensions?.tags?.name || attributeName | ||
+ return this.coerceToGraphQLName(name); | ||
}, | ||
}), | ||
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.