Code Monkey home page Code Monkey logo

Comments (6)

FelixZY avatar FelixZY commented on July 18, 2024 1

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 :)

from crystal.

FelixZY avatar FelixZY commented on July 18, 2024
  1. can be addressed using the @graphile/simplify-inflection plugin. See also https://postgraphile.org/postgraphile/next/inflection#advice

from crystal.

benjie avatar benjie commented on July 18, 2024

Point 1

Hi @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 profile_type and we already generate a type ProfileType to represent the possible types of the interface Profile and that caused issues. Ideally we'd use the same enum, but we're not smart enough for that yet (please feel free to file a separate issue if you're so inclined). So I had to write a quick inflection plugin to rename the builtin type to ProfilePolyType; I suggest you replace that with something more suitable (or disable PgPolymorphismOnlyArgumentPlugin):

 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 2

You should consider using @graphile/simplify-inflection; but you're right that's a super weird naming issue. Please file a separate issue about it ❤️ Filed as #2082 (In general, each issue should be filed in a separate issue; it makes them easier to track and address.)

Point 3

Hopefully @graphile/simplify-inflection will address that.

Point 4

I didn't think polymorphic types supported any CRUD mutations; if they do then this is a bug, please file it as a separate issue filed as #2083.

Point 5

I think so; please use a plugin like:

function makeRuruTitlePlugin(title: string): GraphileConfig.Plugin {
return {
name: "RuruTitlePlugin",
version: "0.0.0",
grafserv: {
middleware: {
ruruHTMLParts(next, event) {
const { htmlParts, request } = event;
htmlParts.titleTag = `<title>${escapeHTML(
title + " | " + request.getHeader("host"),
)}</title>`;
return next();
},
},
},
};
}

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 ❤️

from crystal.

FelixZY avatar FelixZY commented on July 18, 2024

4

I didn't think polymorphic types supported any CRUD mutations; if they do then this is a bug

I don't know if they do - based on your feedback on 1., I probably did not configure polymorphism properly.

from crystal.

benjie avatar benjie commented on July 18, 2024

Ah 🤦‍♂️ I should have thought of that! Closing #2083; please re-open if it does turn out to be an issue.

from crystal.

FelixZY avatar FelixZY commented on July 18, 2024

For future reference: the PgPolymorphismOnlyArgumentPlugin has description "Adds the 'only' argument to polymorphic relations to limit to only the given types". See also

export const PgPolymorphismOnlyArgumentPlugin: GraphileConfig.Plugin = {

from crystal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.