Skip to content

Commit 375f125

Browse files
author
mattia rossi
committed
Updated postgraphile/grafast/pg packages, added EXPORTABLE calls to all sql methods
1 parent d10027e commit 375f125

7 files changed

Lines changed: 924 additions & 622 deletions

__tests__/integration/queries.test.ts

Lines changed: 125 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ import * as path from "path";
33
import * as pg from "pg";
44

55
import { promisify } from "util";
6-
import { ExecutionArgs, GraphQLSchema, parse, validate } from "graphql";
6+
import {
7+
ExecutionArgs,
8+
GraphQLError,
9+
GraphQLSchema,
10+
parse,
11+
validate,
12+
} from "graphql";
713
import { withPgClient, withPgPool } from "../helpers";
814
import { PgConditionArgumentPlugin } from "graphile-build-pg";
915
import { postgraphilePresetAmber } from "postgraphile/presets/amber";
1016
import { makeV4Preset, V4Options } from "postgraphile/presets/v4";
1117
import { makeSchema } from "postgraphile";
1218
import { PostGraphileConnectionFilterPreset } from "../../src/index";
1319
import CustomOperatorsPlugin from "./../customOperatorsPlugin";
14-
import { execute, hookArgs } from "grafast";
20+
import { execute, hookArgs, isSafeError } from "grafast";
1521
import { SchemaResult } from "graphile-build";
1622
import { makeWithPgClientViaPgClientAlreadyInTransaction } from "@dataplan/pg/adaptors/pg";
1723
import { exportSchemaAsString } from "graphile-export";
@@ -23,6 +29,7 @@ jest.setTimeout(300000);
2329
const vmEval = (code: string) => {
2430
const { schema } = importFromStringSync(code, {
2531
transformOptions: { loader: "js" },
32+
useCurrentGlobal: true,
2633
});
2734
return schema as GraphQLSchema;
2835
};
@@ -117,36 +124,66 @@ beforeAll(async () => {
117124
nullAndEmptyAllowed,
118125
addConnectionFilterOperator,
119126
] = await Promise.all([
120-
createPostGraphileSchema(pool, ["p"], {
121-
skipPlugins: [PgConditionArgumentPlugin],
122-
}),
123-
createPostGraphileSchema(pool, ["p"], {
124-
skipPlugins: [PgConditionArgumentPlugin],
125-
dynamicJson: true,
126-
}),
127-
createPostGraphileSchema(pool, ["p"], {
128-
skipPlugins: [PgConditionArgumentPlugin],
129-
graphileBuildOptions: {
130-
pgUseCustomNetworkScalars: true,
127+
createPostGraphileSchema(
128+
pool,
129+
["p"],
130+
{
131+
skipPlugins: [PgConditionArgumentPlugin],
131132
},
132-
}),
133-
createPostGraphileSchema(pool, ["p"], {
134-
skipPlugins: [PgConditionArgumentPlugin],
135-
graphileBuildOptions: {
136-
connectionFilterRelations: true,
133+
{}
134+
),
135+
createPostGraphileSchema(
136+
pool,
137+
["p"],
138+
{
139+
skipPlugins: [PgConditionArgumentPlugin],
140+
dynamicJson: true,
137141
},
138-
}),
139-
createPostGraphileSchema(pool, ["p"], {
140-
skipPlugins: [PgConditionArgumentPlugin],
141-
simpleCollections: "only",
142-
}),
143-
createPostGraphileSchema(pool, ["p"], {
144-
skipPlugins: [PgConditionArgumentPlugin],
145-
graphileBuildOptions: {
146-
connectionFilterAllowNullInput: true,
147-
connectionFilterAllowEmptyObjectInput: true,
142+
{}
143+
),
144+
createPostGraphileSchema(
145+
pool,
146+
["p"],
147+
{
148+
skipPlugins: [PgConditionArgumentPlugin],
149+
graphileBuildOptions: {
150+
pgUseCustomNetworkScalars: true,
151+
},
148152
},
149-
}),
153+
{}
154+
),
155+
createPostGraphileSchema(
156+
pool,
157+
["p"],
158+
{
159+
skipPlugins: [PgConditionArgumentPlugin],
160+
graphileBuildOptions: {
161+
connectionFilterRelations: true,
162+
},
163+
},
164+
{}
165+
),
166+
createPostGraphileSchema(
167+
pool,
168+
["p"],
169+
{
170+
skipPlugins: [PgConditionArgumentPlugin],
171+
simpleCollections: "only",
172+
},
173+
{}
174+
),
175+
createPostGraphileSchema(
176+
pool,
177+
["p"],
178+
{
179+
skipPlugins: [PgConditionArgumentPlugin],
180+
graphileBuildOptions: {
181+
connectionFilterAllowNullInput: true,
182+
connectionFilterAllowEmptyObjectInput: true,
183+
},
184+
},
185+
{}
186+
),
150187
createPostGraphileSchema(
151188
pool,
152189
["p"],
@@ -172,73 +209,66 @@ beforeAll(async () => {
172209

173210
for (const queryFileName of queryFileNames) {
174211
// eslint-disable-next-line jest/valid-title
175-
test(
176-
queryFileName,
177-
async () => {
178-
// Read the query from the file system.
179-
const query = await readFile(
180-
path.resolve(queriesDir, queryFileName),
181-
"utf8"
212+
test(queryFileName, async () => {
213+
// Read the query from the file system.
214+
const query = await readFile(
215+
path.resolve(queriesDir, queryFileName),
216+
"utf8"
217+
);
218+
// Get the appropriate GraphQL schema for this fixture. We want to test
219+
// some specific fixtures against a schema configured slightly
220+
// differently.
221+
const gqlSchemaByQueryFileName: {
222+
[queryFileName: string]: SchemaResult;
223+
} = {
224+
"addConnectionFilterOperator.graphql":
225+
gqlSchemas.addConnectionFilterOperator,
226+
"dynamicJsonTrue.graphql": gqlSchemas.dynamicJson,
227+
"types.cidr.graphql": gqlSchemas.networkScalars,
228+
"types.macaddr.graphql": gqlSchemas.networkScalars,
229+
"arrayTypes.cidrArray.graphql": gqlSchemas.networkScalars,
230+
"arrayTypes.macaddrArray.graphql": gqlSchemas.networkScalars,
231+
"relations.graphql": gqlSchemas.relations,
232+
"simpleCollections.graphql": gqlSchemas.simpleCollections,
233+
"nullAndEmptyAllowed.graphql": gqlSchemas.nullAndEmptyAllowed,
234+
};
235+
const { schema, resolvedPreset } =
236+
queryFileName in gqlSchemaByQueryFileName
237+
? gqlSchemaByQueryFileName[queryFileName]
238+
: gqlSchemas.normal;
239+
const document = parse(query);
240+
const errors = validate(schema, document);
241+
if (errors.length > 0) {
242+
throw new Error(
243+
`GraphQL validation errors:\n${errors.map((e) => e.message).join("\n")}`
182244
);
183-
// Get the appropriate GraphQL schema for this fixture. We want to test
184-
// some specific fixtures against a schema configured slightly
185-
// differently.
186-
const gqlSchemaByQueryFileName: {
187-
[queryFileName: string]: SchemaResult;
188-
} = {
189-
"addConnectionFilterOperator.graphql":
190-
gqlSchemas.addConnectionFilterOperator,
191-
"dynamicJsonTrue.graphql": gqlSchemas.dynamicJson,
192-
"types.cidr.graphql": gqlSchemas.networkScalars,
193-
"types.macaddr.graphql": gqlSchemas.networkScalars,
194-
"arrayTypes.cidrArray.graphql": gqlSchemas.networkScalars,
195-
"arrayTypes.macaddrArray.graphql": gqlSchemas.networkScalars,
196-
"relations.graphql": gqlSchemas.relations,
197-
"simpleCollections.graphql": gqlSchemas.simpleCollections,
198-
"nullAndEmptyAllowed.graphql": gqlSchemas.nullAndEmptyAllowed,
199-
};
200-
const { schema, resolvedPreset } =
201-
queryFileName in gqlSchemaByQueryFileName
202-
? gqlSchemaByQueryFileName[queryFileName]
203-
: gqlSchemas.normal;
204-
205-
const document = parse(query);
206-
const errors = validate(schema, document);
207-
if (errors.length > 0) {
208-
throw new Error(
209-
`GraphQL validation errors:\n${errors
210-
.map((e) => e.message)
211-
.join("\n")}`
212-
);
213-
}
214-
const args: ExecutionArgs = {
215-
schema,
216-
document,
217-
};
218-
await hookArgs(args, resolvedPreset, {});
219-
//const pgSubscriber = new PgSubscriber(pool);
220-
const result = (await withPgClient(async (pgClient) => {
221-
// We must override the context because we didn't use a pool above and so
222-
// we need to add our own client
245+
}
246+
const args: ExecutionArgs = {
247+
schema,
248+
document,
249+
};
250+
await hookArgs(args, resolvedPreset, {});
251+
//const pgSubscriber = new PgSubscriber(pool);
252+
const result = (await withPgClient(async (pgClient) => {
253+
// We must override the context because we didn't use a pool above and so
254+
// we need to add our own client
223255

224-
// NOTE: the withPgClient needed on context is **VERY DIFFERENT** to our
225-
// withPgClient test helper. We should rename our test helper ;)
226-
const contextWithPgClient =
227-
makeWithPgClientViaPgClientAlreadyInTransaction(pgClient, false);
228-
try {
229-
args.contextValue = {
230-
pgSettings: (args.contextValue as any).pgSettings,
231-
withPgClient: contextWithPgClient,
232-
//pgSubscriber,
233-
};
256+
// NOTE: the withPgClient needed on context is **VERY DIFFERENT** to our
257+
// withPgClient test helper. We should rename our test helper ;)
258+
const contextWithPgClient =
259+
makeWithPgClientViaPgClientAlreadyInTransaction(pgClient, false);
260+
try {
261+
args.contextValue = {
262+
pgSettings: (args.contextValue as any).pgSettings,
263+
withPgClient: contextWithPgClient,
264+
//pgSubscriber,
265+
};
234266

235-
return (await execute(args)) as any;
236-
} finally {
237-
contextWithPgClient.release?.();
238-
}
239-
})) as any;
240-
expect(result).toMatchSnapshot();
241-
},
242-
100000000
243-
);
267+
return (await execute(args)) as any;
268+
} finally {
269+
contextWithPgClient.release?.();
270+
}
271+
})) as any;
272+
expect(result).toMatchSnapshot();
273+
});
244274
}

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
},
2727
"dependencies": {
2828
"eslint-plugin-graphile-export": "^0.0.2-beta.3",
29-
"graphile-export": "^0.0.2-beta.4",
29+
"graphile-export": "0.0.2-beta.6",
3030
"tslib": "^2.5.0"
3131
},
3232
"devDependencies": {
3333
"@babel/eslint-parser": "^7.22.11",
3434
"@babel/plugin-transform-runtime": "^7.23.3",
3535
"@babel/preset-env": "^7.22.14",
3636
"@babel/preset-typescript": "^7.22.11",
37-
"@dataplan/pg": "^0.0.1-beta.1",
37+
"@dataplan/pg": "0.0.1-beta.12",
3838
"@tsconfig/node16": "^1.0.3",
3939
"@types/jest": "29.5.0",
4040
"@typescript-eslint/eslint-plugin": "^6.5.0",
@@ -49,22 +49,22 @@
4949
"eslint-plugin-simple-import-sort": "^10.0.0",
5050
"eslint-plugin-tsdoc": "^0.2.17",
5151
"eslint_d": "^12.2.1",
52-
"grafast": "^0.0.1-beta.1",
53-
"grafserv": "^0.0.1-beta.1",
52+
"grafast": "0.1.1-beta.1",
53+
"grafserv": "0.1.1-beta.3",
5454
"graphile-build": "^5.0.0-beta.1",
55-
"graphile-build-pg": "^5.0.0-beta.1",
55+
"graphile-build-pg": "5.0.0-beta.15",
5656
"graphql": "16.1.0-experimental-stream-defer.6",
57-
"jest": "29.5.0",
57+
"jest": "29.7.0",
5858
"module-from-string": "^3.3.0",
59-
"pg": "8.8.0",
60-
"pg-introspection": "^0.0.1-beta.1",
61-
"pg-sql2": "^5.0.0-beta.1",
62-
"postgraphile": "^5.0.0-beta.1",
59+
"pg": "8.11.3",
60+
"pg-introspection": "0.0.1-beta.4",
61+
"pg-sql2": "5.0.0-beta.4",
62+
"postgraphile": "5.0.0-beta.16",
6363
"prettier": "2.8.7",
6464
"ts-jest": "29.1.0",
6565
"typescript": "^5.0.4"
6666
},
6767
"files": [
6868
"dist"
6969
]
70-
}
70+
}

src/AddConnectionFilterOperatorPlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GraphQLInputType } from "graphql";
22
import { $$filters } from "./interfaces";
33
import { makeApplyPlanFromOperatorSpec } from "./PgConnectionArgFilterOperatorsPlugin";
4+
import { EXPORTABLE } from "graphile-export";
45

56
const { version } = require("../package.json");
67

@@ -117,7 +118,7 @@ export const AddConnectionFilterOperatorPlugin: GraphileConfig.Plugin = {
117118
);
118119
}
119120

120-
return fields;
121+
return EXPORTABLE((fields) => fields, [fields]);
121122
},
122123
},
123124
},

src/PgConnectionArgFilterAttributesPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const PgConnectionArgFilterAttributesPlugin: GraphileConfig.Plugin = {
9898
) {
9999
throw Object.assign(
100100
new Error(
101-
`Null literals are forbidden in filter argument input. - AllowNullInput: ${connectionFilterAllowNullInput}`
101+
"Null literals are forbidden in filter argument input."
102102
),
103103
{
104104
//TODO: mark this error as safe

0 commit comments

Comments
 (0)