-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
Questions based on initial experience with v5 polymorphism #2077
Comments
|
Point 1Hi @FelixZY; thanks for the great reproduction! I trimmed it down a bit further so I wouldn't need to provide a bunch of envvars, and I had to tweak your seed.sql file as it missed the schema in a couple places, but it was quite easy to reproduce your issue. It was a simple one, smart comments must be the first things in a comment, but you had them as the last things. (See below for fixed SQL.) This was visible in GraphiQL as the smart tags were coming through into the documentation when you hovered over fields, whereas they should have been removed. Once I resolved this, I then faced the issue that you called your type import { PostGraphileAmberPreset } from "postgraphile/presets/amber";
import { PostGraphileRelayPreset } from "postgraphile/presets/relay";
import { makePgService } from "postgraphile/adaptors/pg";
const connectionString = `postgres:///felixzy`;
/** @type {GraphileConfig.Preset} */
const preset = {
extends: [PostGraphileAmberPreset, PostGraphileRelayPreset],
pgServices: [
makePgService({
connectionString,
superuserConnectionString: connectionString,
pubsub: true,
schemas: ["dansdata"],
}),
],
gather: {
pgStrictFunctions: true,
installWatchFixtures: true,
},
schema: {
dontSwallowErrors: true,
jsonScalarAsString: false,
pgForbidSetofFunctionsToReturnNull: true,
},
grafserv: {
graphiql: true,
graphqlOverGET: false,
watch: true,
},
grafast: {
explain: true,
},
+ plugins: [
+ {
+ name: "RenamePolymorphismOnlyTypePlugin",
+ inflection: {
+ replace: {
+ pgPolymorphismEnumType(prev, options, pgCodec) {
+ return this.upperCamelCase(`${this._codecName(pgCodec)}-poly-type`);
+ },
+ },
+ },
+ },
+ ],
};
export default preset; Here's the SQL I used: DROP SCHEMA if EXISTS "dansdata" CASCADE;
CREATE SCHEMA "dansdata";
CREATE TYPE dansdata.profile_type AS ENUM ('individual');
CREATE TABLE dansdata.profiles (
id UUID DEFAULT gen_random_uuid () PRIMARY KEY,
type dansdata.profile_type NOT NULL,
name TEXT NOT NULL
);
comment ON TABLE dansdata.profiles IS $$
@interface mode:relational type:type
@type individual references:individuals
@name Profile
Represents an entity with profile data.
$$;
CREATE TABLE dansdata.individuals (
id UUID PRIMARY KEY REFERENCES dansdata.profiles (id) ON DELETE CASCADE
);
comment ON TABLE dansdata.individuals IS $$
@name Individual
Represents an individual person.
$$; Once you get this working, submitting some examples to the documentation would be appreciated! Point 2You should consider using @graphile/simplify-inflection; but you're right that's a super weird naming issue. Point 3Hopefully @graphile/simplify-inflection will address that. Point 4I didn't think polymorphic types supported any CRUD mutations; if they do then this is a bug, Point 5I think so; please use a plugin like: crystal/postgraphile/postgraphile/graphile.config.ts Lines 85 to 102 in 91e87ab
TypeScript should give you some guidance. If you get it working, I'd love it if you could contribute an example back to the docs. Closing this since issue 1 is dealt with, please file any separate issues as separate issues ❤️ |
Thanks a lot @benjie ! Sorry about the "multi-bug" - I wasn't sure any one of them were significant enough to post about. I'll be happy to provide some PRs once I'm done with my current queue :) |
4
I don't know if they do - based on your feedback on 1., I probably did not configure polymorphism properly. |
Ah 🤦♂️ I should have thought of that! Closing #2083; please re-open if it does turn out to be an issue. |
For future reference: the crystal/graphile-build/graphile-build-pg/src/plugins/PgPolymorphismOnlyArgumentPlugin.ts Line 37 in 73fd6f0
|
This was mentioned by @benjie in graphile#2077 and graphile#2083 but does not appear to have been explicitly documented yet.
Summary
I started experimenting a bit with the new polymorphism in v5 tonight and found myself wondering about a few different things.
Additional context
PostgreSQL: docker -
postgis/postgis:16-3.4-alpine
Node: 20.13.1
Postgraphile: 5.0.0-beta.26
Setup:
graphile.config.mjs
seed.sql
I also tried the
@interface mode:union
/@implements Profile
version of the above (without theprofiles.type
column).1. Include example queries in documentation
The documentation is quite clear in how one should use the smart comments to configure polymorphism. Good work!
I am however, missing examples of what effect this has on the syntax of graphql queries. For example, I'm currently forced to write
whereas I would expect to write
I cannot figure out if I'm doing something wrong or if this is the intended behavior as the documentation does not describe the intended GraphQL syntax.
2.
PostGraphileRelayPreset
does not eliminateRow
inByRowId
PostGraphileRelayPreset
is suggested as a way to hide the uglyrowId
from your schema. This does work. However, connections are still generated using theByRowId
syntax. Even worse, it seems generatedByRowId
connections do not actually expect therowId
after enablingPostGraphileRelayPreset
! Instead, the value returned from theid
is expected. This becomes confusing very quickly.Current:
Expected
3. I would like to drop the
ByRowId
when accessing parent propertiesNot sure how to do this. I'm guessing I'd have to write some kind of custom plugin? It would be nice if it was the default though.
Current:
Expected
Even better
4. I can't find a way to create a
Profile
when creating anIndividual
In my system, a
Profile
is always one of a few given types. It is unexpected that aProfile
should be created without an associated e.g.Individual
. Preferably, I would like to removecreateProfile
from my mutations altogether and expose only e.g.createIndividual
. However, this meanscreateIndividual
needs to be able to create the baseProfile
, which it seems is not possible?Current
Expected
5. Custom startup text in graphiql
I'm planning to use Postgraphile to expose a free API for third parties. I would therefore like to change the default text in graphiql/Ruru to link to related resources. Is this possible?
Default text
The text was updated successfully, but these errors were encountered: