Comments (2)
This was resolved via Discord chat. The following is a summary..
Definition of PgManytoManyInflector:
import GraphileUtils from 'graphile-utils'
const { makeAddInflectorsPlugin } = GraphileUtils
export default makeAddInflectorsPlugin(
{
manyToManyRelationByKeys (
_leftKeyAttributes,
_junctionLeftKeyAttributes,
_junctionRightKeyAttributes,
_rightKeyAttributes,
_junctionTable,
rightTable,
_junctionLeftConstraint,
junctionRightConstraint
) {
if (junctionRightConstraint.tags.manyToManyFieldName) {
return junctionRightConstraint.tags.manyToManyFieldName
}
return this.camelCase(
`${this.pluralize(this._singularizedTableName(rightTable))}`
)
},
manyToManyRelationByKeysSimple (
_leftKeyAttributes,
_junctionLeftKeyAttributes,
_junctionRightKeyAttributes,
_rightKeyAttributes,
_junctionTable,
rightTable,
_junctionLeftConstraint,
junctionRightConstraint
) {
if (junctionRightConstraint.tags.manyToManySimpleFieldName) {
return junctionRightConstraint.tags.manyToManySimpleFieldName
}
return this.camelCase(
`${this.pluralize(this._singularizedTableName(rightTable))}`
)
}
},
true
)
It's working as expected. The many-to-many plugin adds additional fields to your GraphQL types by looking for foreign keys that lead to junction tables. In your case, the plugin is trying to add two fields on your User
type that have a many-to-many relationship with your Image
type:
- The first represents the path from users -> articles.author_id -> articles.cover_id -> images
- The second represents the path from users -> articles.updater_id -> articles.cover_id -> images
Your PgManyToManyInflector plugin is trying to simplify the field names by simply calling the field images
, but in this case, images
could mean either the article images as an author or the article images as an updater. PostGraphile detects this field name conflict and throws the error.
This why the ManyToMany plugin has to use such verbose names by default.. it's the only way to prevent conflicts like this. Simply using the other table's name will work.. until you have two paths to the table, like this case.
To fix this, you can either:
- Add some extra logic to your Inflector plugin.. essentially an extra if statement that catches these cases and assigns custom field names; or
- Wait for the implementation of
@omit manyToMany
(see #11) and then omit one (or both) of the fields that caused the conflict.
The first approach would look something like this:
// Just before the final return statement in the custom inflector..
if (
junctionTable.name === "articles" &&
rightTable.name === "images" &&
junctionLeftKeyAttributes.length === 1 &&
junctionLeftKeyAttributes[0].name === "author_id"
) {
return this.camelCase(
`author-article-${this.pluralize(this._singularizedTableName(rightTable))}`
);
}
if (
junctionTable.name === "articles" &&
rightTable.name === "images" &&
junctionLeftKeyAttributes.length === 1 &&
junctionLeftKeyAttributes[0].name === "updater_id"
) {
return this.camelCase(
`updater-article-${this.pluralize(this._singularizedTableName(rightTable))}`
);
}
With this approach you'll end up with authorArticleImages
and updaterArticleImages
fields.
from pg-many-to-many.
By the way, if you can think of a way to make these errors better, let me know
from pg-many-to-many.
Related Issues (20)
- Comment on foreign key constraint ignored for simple collections HOT 3
- Support ommitting fields with smart comments HOT 13
- Support @simpleCollections smart comments on the foreign key HOT 1
- Support for many to many relationships of the same type? HOT 2
- many-to-many and pg-simplify-inflector HOT 3
- error generating relationship between tables HOT 4
- Naming conflict when replacing default relations HOT 3
- Common problems on install? HOT 2
- @omit read on tables HOT 3
- Multi column keys.
- Exposing Edge properties in "Simple Collections" HOT 2
- Smart comments on views HOT 1
- typescript error HOT 3
- Plugin is undefined on initialization HOT 4
- Enable for only linker tables
- Does pg-many-to-many require 4.1.0, or 4.1.0 or later? HOT 1
- TypeScript type declares a default export, but library doesn't set `modules.export.default` HOT 1
- @omit JoinTable
- Error: Cannot find module 'debug' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pg-many-to-many.