Skip to content

Commit

Permalink
add a reproducible for steps order issue in a mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
hos committed Dec 13, 2024
1 parent e3bcd55 commit 9c290e3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 28 deletions.
81 changes: 54 additions & 27 deletions graphile.config.mjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
// @ts-check
import { makePgService } from "@dataplan/pg/adaptors/pg";
import AmberPreset from "postgraphile/presets/amber";
import { makeV4Preset } from "postgraphile/presets/v4";
import { makePgSmartTagsFromFilePlugin } from "postgraphile/utils";
import { PostGraphileConnectionFilterPreset } from "postgraphile-plugin-connection-filter";
import { PgAggregatesPreset } from "@graphile/pg-aggregates";
import { PgManyToManyPreset } from "@graphile-contrib/pg-many-to-many";
// import { PgSimplifyInflectionPreset } from "@graphile/simplify-inflection";
import PersistedPlugin from "@grafserv/persisted";
import { PgOmitArchivedPlugin } from "@graphile-contrib/pg-omit-archived";
import { dirname } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import { sideEffect } from "postgraphile/grafast";
import { makeWrapPlansPlugin } from "postgraphile/utils";

// For configuration file details, see: https://postgraphile.org/postgraphile/next/config
export const UserPlugin = makeWrapPlansPlugin((build) => {
const { users } = build.input.pgRegistry.pgResources;

const TagsFilePlugin = makePgSmartTagsFromFilePlugin(`${__dirname}/tags.json5`);
return {
Mutation: {
updateUserByRowId: {
plan(plan, $source, { $input: { $rowId } }) {
const $before = users.find({ id: $rowId }).single();

const $valueBefore = $before.get("value1");
// Uncomment this line and it will have both values, prev and new,
// instead of having both values as new.
// $valueBefore.hasSideEffects = true;

const $plan = plan();
const $update = $plan.get("result");
const $valueAfter = $update.get("value1");

sideEffect(
[$valueBefore, $valueAfter],
async ([valueBefore, valueAfter]) => {
console.log(`[valueBefore, valueAfter]`, [
valueBefore,
valueAfter,
]);
}
);

return $plan;
},
},
},
};
});

/** @satisfies {GraphileConfig.Preset} */
const preset = {
extends: [
AmberPreset.default ?? AmberPreset,
makeV4Preset({
/* Enter your V4 options here */
graphiql: true,
graphiqlRoute: "/",
}),
PostGraphileConnectionFilterPreset,
PgManyToManyPreset,
PgAggregatesPreset,
// PostGraphileConnectionFilterPreset,
// PgManyToManyPreset,
// PgAggregatesPreset,
// PgSimplifyInflectionPreset
],
plugins: [PersistedPlugin.default, PgOmitArchivedPlugin, TagsFilePlugin],
plugins: [
UserPlugin,
// PersistedPlugin.default,
// PgOmitArchivedPlugin,
// TagsFilePlugin,
],
pgServices: [
makePgService({
// Database connection string:
connectionString: process.env.DATABASE_URL,
// connectionString: process.env.DATABASE_URL,
// superuserConnectionString: process.env.SUPERUSER_DATABASE_URL ?? process.env.DATABASE_URL,
// schemas: process.env.DATABASE_SCHEMAS?.split(",") ?? ["public"],
connectionString:
"postgresql://postgres:postgres@localhost:5432/reproducible",
superuserConnectionString:
process.env.SUPERUSER_DATABASE_URL ?? process.env.DATABASE_URL,
// List of schemas to expose:
process.env.SUPERUSER_DATABASE_URL ??
"postgresql://postgres:postgres@localhost:5432/reproducible",
schemas: process.env.DATABASE_SCHEMAS?.split(",") ?? ["public"],
// Enable LISTEN/NOTIFY:
pubsub: true,
Expand All @@ -49,12 +74,14 @@ const preset = {
grafserv: {
port: 5678,
websockets: true,
allowUnpersistedOperation: true,
watch: true,
},
grafast: {
explain: true,
},
schema: {
defaultBehavior: "-connection",
},
};

export default preset;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
},
"prettier": {
"proseWrap": "always"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
19 changes: 19 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
drop table if exists public.users;

create table public.users (
id int generated always as identity primary key,
value1 text,
value2 text
);

insert into public.users (value1, value2) values ('value1', 'value2');

grant insert on public.users to public;
grant update on public.users to public;

alter table public.users enable row level security;

create policy select_policy on public.users for select using (true);
create policy insert_policy on public.users for insert with check (true);
create policy update_policy on public.users for update using (true);
create policy delete_policy on public.users for delete using (true);

0 comments on commit 9c290e3

Please sign in to comment.