Comments (8)
You can manually add a where function to filter out the rows with NULL values at that column.
I'm going to make a patch to do a null check before attempting to call toSQL
inside the function so that it does not throw an exception.
from join-monster.
Yes this is possible. Just add a where
function beside the sqlBatch.
sqlBatch: {
// which column to match up to the users
thisKey: 'post_id',
// the other column to compare to
parentKey: 'id'
},
where: function(table) {
return `${table}."xyz" = 8989`
}
from join-monster.
How do I get the parent (User) type's argument (xyz)? In below code it gives args.id comes as "undefined".
where: (table, args, context) => {
return `${table}.invoice_id = ${args.id}`
}
from join-monster.
Oh I see. Currently, Join Monster does not provide the arguments from a parent field. I'll consider adding that to the callback signature.
For now, you'll have to repeat the argument on the posts
field.
{
user(xyz: 8989) {
fullName
email
posts(xyz: 8989) {
id
body
comments {
id
body
author {
id
fullName
}
}
}
}
}
from join-monster.
I see. Then as a workaround can I use sqlJoin with sqlBatch for satisfying multiple conditions like below? Basically I want the child to form a batch query using multiple conditions.
comments: {
......
sqlJoin: (postTable, commentsTable) => `${postTable}.XYZ = ${commentsTable}.XYZ`
sqlBatch: {
// which column to match up to the users
thisKey: 'post_id',
// the other column to compare to
parentKey: 'id'
}
...
}
which need to result like this:
SELECT
"comments"."id" AS "id",
"comments"."body" AS "body",
"comments"."post_id" AS "post_id"
FROM comments AS "comments"
LEFT JOIN posts AS "posts" ON "comments".XYZ = "posts".XYZ
WHERE "comments"."post_id" IN (2,8,11,12)
from join-monster.
Unfortunately not. When using sqlBatch, a separate query is made, so you do not have access to any values from the users or posts except for the parentKey specified in sqlBatch. You cannot mix sqlJoin with sqlBatch.
Another option is to simply use joins all the way through. So you can replace sqlBatch with sqlJoin.
from join-monster.
ok. Related to sqlBatch, can I put condition to join only when the column value is not null? I get the below error as the column I use in sqlBatch is null for some of the rows. In below case PO_DISTRIBUTION_ID is null which I am using in sqlBatch join.
{ INVOICE_ID: 168295,
INVOICE_NUM: 'ERS-8928-64',
INVOICE_AMOUNT: 109.88,
INVOICE_CURRENCY_CODE: 'USD',
batch__BATCH_ID: 22115,
batch__BATCH_NAME: 'ERS:101',
batch__BATCH_DATE: 2012-05-30T08:00:00.000Z,
batch__LAST_UPDATED_BY: 'WHSE_MGR_M1',
batch__CREATED_BY: 'WHSE_MGR_M1',
'lines__INVOICE_ID#LINE_NUMBER': '1682955',
lines__LINE_NUMBER: 5,
lines__LINE_TYPE_LOOKUP_CODE: 'TAX',
lines__AMOUNT: 4,
lines__PO_DISTRIBUTION_ID: null },
........ +106ms
join-monster 5 rows... +0ms
{ TypeError: Cannot read property 'toSQL' of null
at maybeQuote (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/util.js:95:19)
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:52:45
at Array.map (native)
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:51:57
at Generator.next (<anonymous>)
at step (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:191)
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:437
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:99
at Promise.all.sqlAST.children.map (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:109:22)
at Array.map (native)
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:34:40
at Generator.next (<anonymous>)
at step (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:191)
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:437
at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:99
at nextBatch (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:115:17)
message: 'Cannot read property \'toSQL\' of null',
from join-monster.
Thanks.
from join-monster.
Related Issues (20)
- sqlPaginate always adds total aggregation even if it's not even used HOT 1
- Typescript type errors HOT 1
- Link to demo does not work HOT 5
- tsd failing locally HOT 2
- Fails if I extend GraphQLObjectType HOT 2
- Must call joinMonster in a resolver on a field where the type is decorated with \"sqlTable\" HOT 9
- Cannot read properties of undefined (reading 'sqlTable') HOT 2
- Failing type defs
- Issue with GlobalIDs not transforming back to "native" uuid4 IDs HOT 1
- bug in joinMonster.getNode(): def.args not iterable HOT 4
- Querying the same relation multiple times as aliases with different args results in wrong data HOT 5
- Remove requirement for uniqueKey to be defined HOT 1
- Pagination with dynamic sorting does not support null values. HOT 2
- joinMonster creating invalid MySQL sql HOT 2
- Unsupport many-to-many relation on graphql v15.8 and join-monster v3.1.1 using postgres? HOT 2
- Batching JoinMonster calls
- The HTTP server example code is broken due to deprecation of kao-graphql HOT 1
- join-monster fails to work in a react native deployment HOT 1
- Typescript type error for GraphQLFieldExtensions HOT 1
- Some disjoint fields of the same union type are discarded HOT 7
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 join-monster.