@graphile-contrib/pg-many-to-many
Advanced tools
Comparing version 1.0.0-beta.12 to 1.0.0-beta.13
@@ -22,3 +22,3 @@ module.exports = function PgManyToManyPlugin(builder, options) { | ||
}; | ||
depends("graphile-build-pg", "^4.4.0"); | ||
depends("graphile-build-pg", "^4.5.0"); | ||
@@ -25,0 +25,0 @@ // Register this plugin |
{ | ||
"name": "@graphile-contrib/pg-many-to-many", | ||
"version": "1.0.0-beta.12", | ||
"version": "1.0.0-beta.13", | ||
"description": "Add connection fields for many-to-many relations", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint **/*.js", | ||
"lint": "eslint .", | ||
"test": "scripts/test" | ||
@@ -26,8 +26,12 @@ }, | ||
"jest": "^24.9.0", | ||
"jest-serializer-graphql-schema": "^4.4.6-alpha.0", | ||
"pg": "^7.12.1", | ||
"postgraphile-core": "4.4.0", | ||
"postgraphile-core": "4.5.0", | ||
"prettier": "1.18.2" | ||
}, | ||
"jest": { | ||
"testRegex": "__tests__/.*\\.test\\.js$" | ||
"testRegex": "__tests__/.*\\.test\\.js$", | ||
"snapshotSerializers": [ | ||
"jest-serializer-graphql-schema" | ||
] | ||
}, | ||
@@ -34,0 +38,0 @@ "files": [ |
@@ -7,3 +7,3 @@ # @graphile-contrib/pg-many-to-many | ||
> Requires `postgraphile@^4.4.0` or `graphile-build-pg@^4.4.0` | ||
> Requires `postgraphile@^4.5.0` or `graphile-build-pg@^4.5.0` | ||
@@ -10,0 +10,0 @@ Example: |
@@ -103,4 +103,21 @@ module.exports = function PgManyToManyRelationInflectionPlugin(builder) { | ||
}, | ||
/* eslint-disable no-unused-vars */ | ||
manyToManyRelationSubqueryName( | ||
leftKeyAttributes, | ||
junctionLeftKeyAttributes, | ||
junctionRightKeyAttributes, | ||
rightKeyAttributes, | ||
junctionTable, | ||
rightTable, | ||
junctionLeftConstraint, | ||
junctionRightConstraint, | ||
leftTableTypeName | ||
) { | ||
/* eslint-enable no-unused-vars */ | ||
return `many-to-many-subquery-by-${this._singularizedTableName( | ||
junctionTable | ||
)}`; | ||
}, | ||
}); | ||
}); | ||
}; |
@@ -150,16 +150,34 @@ const createManyToManyConnectionType = require("./createManyToManyConnectionType"); | ||
innerQueryBuilder.where( | ||
sql.fragment`${rightTableAlias}.${sql.identifier( | ||
rightKeyAttribute.name | ||
)} in (select ${sql.identifier( | ||
junctionRightKeyAttribute.name | ||
)} from ${sql.identifier( | ||
const subqueryName = inflection.manyToManyRelationSubqueryName( | ||
leftKeyAttributes, | ||
junctionLeftKeyAttributes, | ||
junctionRightKeyAttributes, | ||
rightKeyAttributes, | ||
junctionTable, | ||
rightTable, | ||
junctionLeftConstraint, | ||
junctionRightConstraint | ||
); | ||
const subqueryBuilder = innerQueryBuilder.buildNamedChildSelecting( | ||
subqueryName, | ||
sql.identifier( | ||
junctionTable.namespace.name, | ||
junctionTable.name | ||
)} where ${sql.identifier( | ||
), | ||
sql.identifier(junctionRightKeyAttribute.name) | ||
); | ||
subqueryBuilder.where( | ||
sql.fragment`${sql.identifier( | ||
junctionLeftKeyAttribute.name | ||
)} = ${leftTableAlias}.${sql.identifier( | ||
leftKeyAttribute.name | ||
)})` | ||
)}` | ||
); | ||
innerQueryBuilder.where( | ||
() => | ||
sql.fragment`${rightTableAlias}.${sql.identifier( | ||
rightKeyAttribute.name | ||
)} in (${subqueryBuilder.build()})` | ||
); | ||
}, | ||
@@ -166,0 +184,0 @@ queryBuilder.context, |
48315
1087
10