New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(utils): @pgQuery support for scalars #534
Conversation
As for that failing test... I have no idea what that means. Doesn't seem to fail in every environment? |
e52c2d9
to
5903b90
Compare
Okay, figured it out - my test-SQL needed a CAST for Postgres 9. Tests are now working fine :) |
Awesome; from a superficial glance this looks great but I'll try and review it properly next week. In the mean time, please change your |
5903b90
to
cdd96b0
Compare
sure thing 👍 |
], | ||
}); | ||
const printedSchema = printSchema(schema); | ||
expect(printedSchema).toMatchSnapshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #533 lands, can you rebase this pull request on top of it and simplify this test? You'll no longer need to call printSchema()
yourself, you can just do expect(schema).toMatchSnapshot()
. 😄
I'm not sure when that PR will land, but I wanted to give you a heads-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do, please ping me when it lands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice; this seems to work well! Couple minor bits of feedback to address, plus I just merged #533 so please rebase and regenerate your snapshots 👍
fragment: ${embed(sql.fragment`(SELECT 100)`)} | ||
) | ||
myCustomScalarWithFunction: Int! @pgQuery( | ||
fragment: ${embed(queryBuilder => sql.fragment`(SELECT 101)`)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to test references to the graphile_utils.users
table itself, so please can you change this to return a String
and do something like:
fragment: ${embed(queryBuilder => sql.fragment`(SELECT 101)`)} | |
fragment: ${embed(queryBuilder => sql.fragment`(${queryBuilder.getTableAlias()}.name || ' ' || ${queryBuilder.getTableAlias()}.email)`)} |
name | ||
myCustomScalar | ||
myCustomScalarWithFunction | ||
myCustomScalarWithFunctionAndArgument(test: 102) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that these work as expected with aliases too, please.
myCustomScalarWithFunctionAndArgument(test: 102) | |
myCustomScalarWithFunctionAndArgument(test: 102) | |
m103: myCustomScalarWithFunctionAndArgument(test: 103) | |
m104: myCustomScalarWithFunctionAndArgument(test: 104) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing you want one alias for each one of them, not the same one twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are different aliases? You might have missed the red line was a deletion... not sure why GitHub did that 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, but they were both aliases for myCustomScalarWithFunctionAndArgument
, so I wasn't sure if that was really your intention or if you wanted one alias for myCustomScalar
, one for myCustomScalarWithFunctionAndArgument
, etc.
ah well, seems like what I did worked out for you :D
extend type User { | ||
myCustomArrayOfScalars: [String!]! @pgQuery( | ||
fragment: ${embed( | ||
sql.fragment`array(SELECT name from ${sql.fragment`graphile_utils.pets`})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is equivalent to:
sql.fragment`array(SELECT name from ${sql.fragment`graphile_utils.pets`})` | |
sql.fragment`array(SELECT name from graphile_utils.pets)` |
I've never used the array constructor in this way; I've always done select array_agg(name) from ...
instead. It seems that this might actually be faster because it's simpler so I should definitely experiment with its usage in PostGraphile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed: #543
cdd96b0
to
400c2d1
Compare
@benjie I think I adressed everything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! If you have a few more minutes it would be great if you could incorporate this into the makeExtendSchemaPlugin docs: https://github.com/graphile/graphile.github.io/edit/develop/src/pages/postgraphile/make-extend-schema-plugin.md
We had already chatted about this - this PR allows for scalars to be added as subqueries using the
@pgQuery
directive with thefragment
argument.If this is merged, it would be great if you could mention my employer Mayflower in the release notes, as this PR was done on company time. But if this something you don't do, thats fine, too 😃