Comments (3)
We need to add it to https://postgraphile.org/postgraphile/next/node-id/
and cross-link it to https://postgraphile.org/postgraphile/next/smart-tags/#arg0variant-arg1variant-
and I could have sworn that I'd written it in the docs somewhere but I can't find it (please PR!) but essentially you need to:
- create the function so that it accepts a table record type rather than uuid (this is a temporary requirement we hope to lift at some point, but we'll need another way of indicating the expected type)
- override autodetection if it's a stable function (as we might detect it as a computed column function) to turn it back into what it should be:
@behavior -queryField -typeField -mutationField +queryField
. No action necessary for yours since it'svolatile
- change the "variant" of the relevant 0-indexed argument to
nodeId
:@arg0variant nodeId\n@arg1variant nodeId
So for you:
CREATE
OR REPLACE function dansdata.add_organization_member (
organization dansdata.organizations,
individual dansdata.individuals,
title TEXT
) returns dansdata.organization_members AS $$
INSERT INTO dansdata.organization_members("organization_id", "individual_id", "title") VALUES (organization.id, individual.id, title) RETURNING *;
$$ language sql volatile strict security invoker;
comment on function dansdata.add_organization_member is
E'@arg0variant nodeId\n@arg1variant nodeId\n@behavior -typeField +mutationField';
from crystal.
I'm well aware of the limitations, and this is a planned feature. The reason we don't support it on UUID
currently is because we have no way of indicating what type that UUID is meant to be, other than to use a record type. Likely a better solution is to use something like @arg0variant nodeId:Organization
but implementing that is not something that has been visited yet. But since it is solvable in the current system (albeit slightly awkward) it's on the backburner to address once V5.0.0 is released.
from crystal.
@benjie, thanks to your description, I was able to implement the desired behavior. However, given the current requirement of using a table record type, I found myself having to deal with two instances of "ugly" DX. For me, these are further motivating the need to support @arg0variant nodeId
on non-table record types, such as uuid
, in the future as well.
1. id
duplication
CREATE OR REPLACE function dansdata.add_organization_member (
organization_id dansdata.organizations,
member_id dansdata.profiles,
title TEXT = NULL
) returns dansdata.organization_members AS $$
SELECT dansdata.add_organization_member (organization_id.id, member_id.id, title);
$$ language sql volatile called ON NULL input security invoker;
As you can see, I now have to use <type>_id.id
syntax to access my id if I want to expose organizationId: <id>
in the GraphQL api.
Of course, I could just
CREATE OR REPLACE function dansdata.add_organization_member (
organization dansdata.organizations,
member dansdata.profiles,
title TEXT = NULL
)
but then the GraphQL member will be named organization
instead of organizationId
(I'm guessing I could work around this with inflection but that's still a bit too much work IMO).
2. It's harder to use the function internally
I can no longer simply do this in raw SQL:
SELECT dansdata.add_organization_member ('68d3ca81-52ba-484d-80b6-ca0af6213c1d', 'f0f98228-e7fe-418c-b71e-995638862ee7');
instead, I've been forced to add a wrapper specifically for postgraphile which I would preferably avoid:
CREATE OR REPLACE function dansdata.add_organization_member (
organization_id UUID,
member_id UUID,
title TEXT = NULL
) returns dansdata.organization_members AS $$
INSERT INTO
dansdata.organization_members ("organization_id", "member_id", "title")
VALUES
(organization_id, member_id, title)
RETURNING
*;
$$ language sql volatile called ON NULL input security invoker;
comment ON function dansdata.add_organization_member IS $$
@behavior -*
$$;
CREATE OR REPLACE function dansdata.postgraphile_add_organization_member (
organization_id dansdata.organizations,
member_id dansdata.profiles,
title TEXT = NULL
) returns dansdata.organization_members AS $$
SELECT dansdata.add_organization_member (organization_id.id, member_id.id, title);
$$ language sql volatile called ON NULL input security invoker;
comment ON function dansdata.postgraphile_add_organization_member IS $$
@name addOrganizationMember
@arg0variant nodeId
@arg1variant nodeId
$$;
from crystal.
Related Issues (20)
- How does Postgraphile integrate with Apache AGE? HOT 1
- Polymorphism - union containing members of an interface plus another; how to plan?
- Create tests for middleware system (grafast, grafserv)
- multi tenancy and update pg schema without restart HOT 1
- Koa middleware does not call next() for all scenarios HOT 7
- (v5) I'd like get a generic executor from `build.input.pgRegistry` inside a `makeExtendSchemaPlugin`. HOT 1
- Questions based on initial experience with v5 polymorphism HOT 6
- The v5 documentation for crud mutations mentions both `insert` and `create` as values for the `@behavior` smart tag. HOT 2
- PgExecutor cache is not cleared between subscription payloads
- Subscription error causes socket to disconnect
- `PostGraphileRelayPreset` does not eliminate `Row` in `ByRowId`
- Polymorphic types offer mutations under some circumstances? HOT 1
- Derived types include selector for the derived types when using relational polymorphism
- It should be possible to declare a shared `@ref` only in the base table when using relational polymporphism HOT 2
- Using `makeWrapPlansPlugin` creates an error when exporting the schema HOT 1
- TypeScript regression: loadOne no longer inferring types HOT 1
- Documentation for `makePgService({adaptorSettings})` appear to be outdated
- Trailing space after `@primaryKe <name>y` smart tag causes error when used with `|` to modify virtual constraint HOT 5
- Ruru rendering issues HOT 2
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 crystal.