Skip to content

Commit c91eb69

Browse files
committed
Solve caching issue
1 parent e226ca8 commit c91eb69

File tree

4 files changed

+31
-42
lines changed

4 files changed

+31
-42
lines changed

createLink.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

createSchema.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { createPostGraphileSchema } = require('postgraphile')
1+
const { createPostGraphileSchema } = require("postgraphile");
22

33
function requireFrom(modules, moduleName) {
4-
const path = [...modules, moduleName].join('/node_modules/')
4+
const path = [...modules, moduleName].join("/node_modules/");
55
try {
66
return require(path); // eslint-disable-line
77
} catch (e) {
@@ -10,46 +10,40 @@ function requireFrom(modules, moduleName) {
1010
const result = requireFrom(
1111
modules.slice(0, modules.length - 1),
1212
moduleName
13-
)
14-
if (result) return result
13+
);
14+
if (result) return result;
1515
}
1616
return (
1717
requireFrom(modules.slice(1), moduleName) ||
1818
requireFrom(modules.slice(0, modules.length - 1), moduleName)
19-
)
19+
);
2020
}
2121
}
2222
const graphileBuild = requireFrom(
23-
['postgraphile', 'postgraphile-core'],
24-
'graphile-build'
25-
)
26-
/*
27-
const graphileBuildPg = requireFrom(
28-
['postgraphile', 'postgraphile-core'],
29-
'postgraphile/node_modules/graphile-build-pg'
30-
)
31-
*/
23+
["postgraphile", "postgraphile-core"],
24+
"graphile-build"
25+
);
3226

33-
const RenamedQueryPlugin = require('./RenamedQueryPlugin')
27+
const RenamedQueryPlugin = require("./RenamedQueryPlugin");
3428

3529
const skipPlugins = [
3630
graphileBuild.QueryPlugin,
3731
graphileBuild.MutationPlugin,
3832
graphileBuild.SubscriptionPlugin,
39-
]
40-
const prependPlugins = [RenamedQueryPlugin]
33+
];
34+
const prependPlugins = [RenamedQueryPlugin];
4135

4236
module.exports = async (pool, schema, options) => {
43-
const schemas = Array.isArray(schema) ? schema : schema.split(',')
37+
const schemas = Array.isArray(schema) ? schema : schema.split(",");
4438
const graphqlSchema = await createPostGraphileSchema(pool, schemas, {
45-
simpleCollections: 'both',
39+
simpleCollections: "both",
4640
dynamicJson: true,
4741
showErrorStack: true,
48-
extendedErrors: ['hint', 'detail', 'errcode'],
49-
legacyRelations: 'omit',
42+
extendedErrors: ["hint", "detail", "errcode"],
43+
legacyRelations: "omit",
5044
...options,
5145
skipPlugins: [...skipPlugins, ...(options.skipPlugins || [])],
5246
prependPlugins: [...prependPlugins, ...(options.prependPlugins || [])],
53-
})
54-
return graphqlSchema
55-
}
47+
});
48+
return graphqlSchema;
49+
};

gatsby-node.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
const gatsbySourceGraphQLNode = require("gatsby-source-graphql/gatsby-node");
2+
const { Pool } = require("pg");
23

3-
const createLink = require("./createLink");
4+
const createSchema = require("./createSchema");
5+
const PostGraphileLink = require("./PostGraphileLink");
46

57
exports.sourceNodes = async (
68
utils,
79
{ typeName = "PostGraphile", fieldName = "postgres", ...options }
810
) => {
11+
const { connectionString, schema: postgresSchema, ...rest } = options;
12+
13+
const pool = new Pool({
14+
connectionString,
15+
});
16+
const graphqlSchema = await createSchema(pool, postgresSchema, rest);
17+
918
await gatsbySourceGraphQLNode.sourceNodes(utils, {
1019
typeName,
1120
fieldName,
12-
createLink: () => createLink(options),
21+
createLink: () => new PostGraphileLink({ pool, schema: graphqlSchema }),
22+
createSchema: () => graphqlSchema,
1323
});
1424
};

performQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = async function performQuery(
88
variables,
99
operationName
1010
) {
11-
const queryString = typeof query === 'string' ? query : print(query);
11+
const queryString = typeof query === "string" ? query : print(query);
1212
return withPostGraphileContext({ pgPool }, async context =>
1313
graphql(
1414
schema, // The schema from `createPostGraphileSchema`

0 commit comments

Comments
 (0)