|
1 | 1 | import * as fs from "fs"; |
2 | 2 | import * as path from "path"; |
3 | 3 | import * as pg from "pg"; |
| 4 | + |
4 | 5 | import { promisify } from "util"; |
5 | | -import { ExecutionArgs, parse, validate } from "graphql"; |
| 6 | +import { |
| 7 | + ExecutionArgs, |
| 8 | + GraphQLError, |
| 9 | + GraphQLSchema, |
| 10 | + parse, |
| 11 | + validate, |
| 12 | +} from "graphql"; |
6 | 13 | import { withPgClient, withPgPool } from "../helpers"; |
7 | 14 | import { PgConditionArgumentPlugin } from "graphile-build-pg"; |
8 | 15 | import { postgraphilePresetAmber } from "postgraphile/presets/amber"; |
9 | 16 | import { makeV4Preset, V4Options } from "postgraphile/presets/v4"; |
10 | 17 | import { makeSchema } from "postgraphile"; |
11 | 18 | import { PostGraphileConnectionFilterPreset } from "../../src/index"; |
12 | 19 | import CustomOperatorsPlugin from "./../customOperatorsPlugin"; |
13 | | -import { execute, hookArgs } from "grafast"; |
| 20 | +import { execute, hookArgs, isSafeError } from "grafast"; |
14 | 21 | import { SchemaResult } from "graphile-build"; |
15 | 22 | import { makeWithPgClientViaPgClientAlreadyInTransaction } from "@dataplan/pg/adaptors/pg"; |
| 23 | +import { exportSchemaAsString } from "graphile-export"; |
| 24 | +import { importFromStringSync } from "module-from-string"; |
16 | 25 |
|
17 | 26 | // TODO: remove this once Grafast gets it's planning under control :D |
18 | | -jest.setTimeout(30000); |
| 27 | +jest.setTimeout(300000); |
| 28 | + |
| 29 | +const vmEval = (code: string) => { |
| 30 | + const { schema } = importFromStringSync(code, { |
| 31 | + transformOptions: { loader: "js" }, |
| 32 | + useCurrentGlobal: true, |
| 33 | + }); |
| 34 | + return schema as GraphQLSchema; |
| 35 | +}; |
19 | 36 |
|
20 | 37 | const createPostGraphileSchema = async ( |
21 | 38 | pool: pg.Pool, |
@@ -44,7 +61,23 @@ const createPostGraphileSchema = async ( |
44 | 61 | ], |
45 | 62 | }; |
46 | 63 | const params = await makeSchema(preset); |
47 | | - return params; |
| 64 | + if (process.env.TEST_EXPORTED_SCHEMA) { |
| 65 | + return { |
| 66 | + ...params, |
| 67 | + schema: vmEval( |
| 68 | + ( |
| 69 | + await exportSchemaAsString(params.schema, { |
| 70 | + mode: "graphql-js", |
| 71 | + // or: |
| 72 | + // mode: "typeDefs", |
| 73 | + modules: {}, |
| 74 | + }) |
| 75 | + ).code |
| 76 | + ), |
| 77 | + }; |
| 78 | + } else { |
| 79 | + return params; |
| 80 | + } |
48 | 81 | }; |
49 | 82 |
|
50 | 83 | const readFile = promisify(fs.readFile); |
@@ -91,36 +124,66 @@ beforeAll(async () => { |
91 | 124 | nullAndEmptyAllowed, |
92 | 125 | addConnectionFilterOperator, |
93 | 126 | ] = await Promise.all([ |
94 | | - createPostGraphileSchema(pool, ["p"], { |
95 | | - skipPlugins: [PgConditionArgumentPlugin], |
96 | | - }), |
97 | | - createPostGraphileSchema(pool, ["p"], { |
98 | | - skipPlugins: [PgConditionArgumentPlugin], |
99 | | - dynamicJson: true, |
100 | | - }), |
101 | | - createPostGraphileSchema(pool, ["p"], { |
102 | | - skipPlugins: [PgConditionArgumentPlugin], |
103 | | - graphileBuildOptions: { |
104 | | - pgUseCustomNetworkScalars: true, |
| 127 | + createPostGraphileSchema( |
| 128 | + pool, |
| 129 | + ["p"], |
| 130 | + { |
| 131 | + skipPlugins: [PgConditionArgumentPlugin], |
| 132 | + }, |
| 133 | + {} |
| 134 | + ), |
| 135 | + createPostGraphileSchema( |
| 136 | + pool, |
| 137 | + ["p"], |
| 138 | + { |
| 139 | + skipPlugins: [PgConditionArgumentPlugin], |
| 140 | + dynamicJson: true, |
| 141 | + }, |
| 142 | + {} |
| 143 | + ), |
| 144 | + createPostGraphileSchema( |
| 145 | + pool, |
| 146 | + ["p"], |
| 147 | + { |
| 148 | + skipPlugins: [PgConditionArgumentPlugin], |
| 149 | + graphileBuildOptions: { |
| 150 | + pgUseCustomNetworkScalars: true, |
| 151 | + }, |
| 152 | + }, |
| 153 | + {} |
| 154 | + ), |
| 155 | + createPostGraphileSchema( |
| 156 | + pool, |
| 157 | + ["p"], |
| 158 | + { |
| 159 | + skipPlugins: [PgConditionArgumentPlugin], |
| 160 | + graphileBuildOptions: { |
| 161 | + connectionFilterRelations: true, |
| 162 | + }, |
105 | 163 | }, |
106 | | - }), |
107 | | - createPostGraphileSchema(pool, ["p"], { |
108 | | - skipPlugins: [PgConditionArgumentPlugin], |
109 | | - graphileBuildOptions: { |
110 | | - connectionFilterRelations: true, |
| 164 | + {} |
| 165 | + ), |
| 166 | + createPostGraphileSchema( |
| 167 | + pool, |
| 168 | + ["p"], |
| 169 | + { |
| 170 | + skipPlugins: [PgConditionArgumentPlugin], |
| 171 | + simpleCollections: "only", |
111 | 172 | }, |
112 | | - }), |
113 | | - createPostGraphileSchema(pool, ["p"], { |
114 | | - skipPlugins: [PgConditionArgumentPlugin], |
115 | | - simpleCollections: "only", |
116 | | - }), |
117 | | - createPostGraphileSchema(pool, ["p"], { |
118 | | - skipPlugins: [PgConditionArgumentPlugin], |
119 | | - graphileBuildOptions: { |
120 | | - connectionFilterAllowNullInput: true, |
121 | | - connectionFilterAllowEmptyObjectInput: true, |
| 173 | + {} |
| 174 | + ), |
| 175 | + createPostGraphileSchema( |
| 176 | + pool, |
| 177 | + ["p"], |
| 178 | + { |
| 179 | + skipPlugins: [PgConditionArgumentPlugin], |
| 180 | + graphileBuildOptions: { |
| 181 | + connectionFilterAllowNullInput: true, |
| 182 | + connectionFilterAllowEmptyObjectInput: true, |
| 183 | + }, |
122 | 184 | }, |
123 | | - }), |
| 185 | + {} |
| 186 | + ), |
124 | 187 | createPostGraphileSchema( |
125 | 188 | pool, |
126 | 189 | ["p"], |
@@ -173,7 +236,6 @@ for (const queryFileName of queryFileNames) { |
173 | 236 | queryFileName in gqlSchemaByQueryFileName |
174 | 237 | ? gqlSchemaByQueryFileName[queryFileName] |
175 | 238 | : gqlSchemas.normal; |
176 | | - |
177 | 239 | const document = parse(query); |
178 | 240 | const errors = validate(schema, document); |
179 | 241 | if (errors.length > 0) { |
|
0 commit comments