postgraphile-core
Advanced tools
Comparing version 4.0.0-alpha.4 to 4.0.0-alpha.5
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.watchPostGraphileSchema = exports.createPostGraphileSchema = exports.postGraphileClassicIdsInflection = exports.postGraphileInflection = exports.postGraphileClassicIdsOverrides = exports.postGraphileBaseOverrides = exports.watchPostGraphQLSchema = exports.createPostGraphQLSchema = exports.postGraphQLClassicIdsInflection = exports.postGraphQLInflection = exports.postGraphQLClassicIdsOverrides = exports.postGraphQLBaseOverrides = exports.inflections = undefined; | ||
exports.watchPostGraphQLSchema = exports.createPostGraphQLSchema = exports.postGraphQLClassicIdsInflection = exports.postGraphQLInflection = exports.postGraphQLClassicIdsOverrides = exports.postGraphQLBaseOverrides = exports.watchPostGraphileSchema = exports.createPostGraphileSchema = exports.postGraphileClassicIdsInflection = exports.postGraphileInflection = exports.postGraphileClassicIdsOverrides = exports.postGraphileBaseOverrides = exports.inflections = undefined; | ||
@@ -43,3 +43,3 @@ var _promise = require("babel-runtime/core-js/promise"); | ||
exports.inflections = _graphileBuildPg.inflections; | ||
const postGraphQLBaseOverrides = exports.postGraphQLBaseOverrides = { | ||
const postGraphileBaseOverrides = exports.postGraphileBaseOverrides = { | ||
enumName(value) { | ||
@@ -50,3 +50,3 @@ return _graphileBuildPg.inflections.defaultUtils.constantCase(_graphileBuildPg.inflections.defaultInflection.enumName(value)); | ||
const postGraphQLClassicIdsOverrides = exports.postGraphQLClassicIdsOverrides = { | ||
const postGraphileClassicIdsOverrides = exports.postGraphileClassicIdsOverrides = { | ||
column(name, _table, _schema) { | ||
@@ -57,5 +57,6 @@ return name === "id" ? "rowId" : _graphileBuildPg.inflections.defaultUtils.camelCase(name); | ||
const postGraphQLInflection = exports.postGraphQLInflection = _graphileBuildPg.inflections.newInflector(postGraphQLBaseOverrides); | ||
const postGraphQLClassicIdsInflection = exports.postGraphQLClassicIdsInflection = _graphileBuildPg.inflections.newInflector((0, _assign2.default)({}, postGraphQLBaseOverrides, postGraphQLClassicIdsOverrides)); | ||
const postGraphileInflection = exports.postGraphileInflection = _graphileBuildPg.inflections.newInflector(postGraphileBaseOverrides); | ||
const postGraphileClassicIdsInflection = exports.postGraphileClassicIdsInflection = _graphileBuildPg.inflections.newInflector((0, _assign2.default)({}, postGraphileBaseOverrides, postGraphileClassicIdsOverrides)); | ||
const awaitKeys = async obj => { | ||
@@ -69,3 +70,3 @@ const result = {}; | ||
const getPostGraphQLBuilder = async (pgConfig, schemas, options = {}) => { | ||
const getPostGraphileBuilder = async (pgConfig, schemas, options = {}) => { | ||
const { | ||
@@ -163,3 +164,3 @@ dynamicJson, | ||
pgColumnFilter: pgColumnFilter || (() => true), | ||
pgInflection: inflector || (classicIds ? postGraphQLClassicIdsInflection : postGraphQLInflection), | ||
pgInflection: inflector || (classicIds ? postGraphileClassicIdsInflection : postGraphileInflection), | ||
nodeIdFieldName: nodeIdFieldName || (classicIds ? "id" : "nodeId"), | ||
@@ -187,5 +188,5 @@ pgJwtTypeIdentifier: jwtPgTypeIdentifier, | ||
const createPostGraphQLSchema = exports.createPostGraphQLSchema = async (pgConfig, schemas, options = {}) => { | ||
const createPostGraphileSchema = exports.createPostGraphileSchema = async (pgConfig, schemas, options = {}) => { | ||
let writeCache; | ||
const builder = await getPostGraphQLBuilder(pgConfig, schemas, (0, _assign2.default)({}, options, { | ||
const builder = await getPostGraphileBuilder(pgConfig, schemas, (0, _assign2.default)({}, options, { | ||
setWriteCacheCallback(fn) { | ||
@@ -203,5 +204,5 @@ writeCache = fn; | ||
*/ | ||
const watchPostGraphQLSchema = exports.watchPostGraphQLSchema = async (pgConfig, schemas, options = {}, onNewSchema) => { | ||
const watchPostGraphileSchema = exports.watchPostGraphileSchema = async (pgConfig, schemas, options = {}, onNewSchema) => { | ||
if (typeof onNewSchema !== "function") { | ||
throw new Error("You cannot call watchPostGraphQLSchema without a function to pass new schemas to"); | ||
throw new Error("You cannot call watchPostGraphileSchema without a function to pass new schemas to"); | ||
} | ||
@@ -212,3 +213,3 @@ if (options.readCache) { | ||
let writeCache; | ||
const builder = await getPostGraphQLBuilder(pgConfig, schemas, (0, _assign2.default)({}, options, { | ||
const builder = await getPostGraphileBuilder(pgConfig, schemas, (0, _assign2.default)({}, options, { | ||
setWriteCacheCallback(fn) { | ||
@@ -232,8 +233,9 @@ writeCache = fn; | ||
const postGraphileBaseOverrides = exports.postGraphileBaseOverrides = postGraphQLBaseOverrides; | ||
const postGraphileClassicIdsOverrides = exports.postGraphileClassicIdsOverrides = postGraphQLClassicIdsOverrides; | ||
const postGraphileInflection = exports.postGraphileInflection = postGraphQLInflection; | ||
const postGraphileClassicIdsInflection = exports.postGraphileClassicIdsInflection = postGraphQLClassicIdsInflection; | ||
const createPostGraphileSchema = exports.createPostGraphileSchema = createPostGraphQLSchema; | ||
const watchPostGraphileSchema = exports.watchPostGraphileSchema = watchPostGraphQLSchema; | ||
// Backwards compat | ||
const postGraphQLBaseOverrides = exports.postGraphQLBaseOverrides = postGraphileBaseOverrides; | ||
const postGraphQLClassicIdsOverrides = exports.postGraphQLClassicIdsOverrides = postGraphileClassicIdsOverrides; | ||
const postGraphQLInflection = exports.postGraphQLInflection = postGraphileInflection; | ||
const postGraphQLClassicIdsInflection = exports.postGraphQLClassicIdsInflection = postGraphileClassicIdsInflection; | ||
const createPostGraphQLSchema = exports.createPostGraphQLSchema = createPostGraphileSchema; | ||
const watchPostGraphQLSchema = exports.watchPostGraphQLSchema = watchPostGraphileSchema; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "postgraphile-core", | ||
"version": "4.0.0-alpha.4", | ||
"version": "4.0.0-alpha.5", | ||
"description": "", | ||
@@ -22,4 +22,4 @@ "main": "node8plus/index.js", | ||
"babel-runtime": ">=6 <7", | ||
"graphile-build": "4.0.0-alpha.1", | ||
"graphile-build-pg": "4.0.0-alpha.4" | ||
"graphile-build": "4.0.0-alpha.5", | ||
"graphile-build-pg": "4.0.0-alpha.5" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
# postgraphile-core | ||
This module implements a compatibility layer between PostGraphQL v4 and | ||
This module implements a compatibility layer between PostGraphile v4 and | ||
`graphile-build`, loading the relevant `graphile-build-pg` plugins and setting | ||
the correct inflector depending on the PostGraphQL options provided. | ||
the correct inflector depending on the PostGraphile options provided. | ||
Unless you want to use the low-level API you probably want to go to the | ||
PostGraphile (previously 'PostGraphQL') repository instead: | ||
[https://github.com/postgraphql/postgraphql](https://github.com/postgraphql/postgraphql) | ||
[https://github.com/graphile/postgraphile](https://github.com/graphile/postgraphile) | ||
@@ -18,3 +18,3 @@ It's also suitable for usage in your own application, but please be aware you | ||
## `createPostGraphQLSchema(pgConfig, schemas, options)` | ||
## `createPostGraphileSchema(pgConfig, schemas, options)` | ||
@@ -26,4 +26,5 @@ This is the function you're most likely to use in production, it will return a | ||
Example: | ||
```js | ||
const schema = await createPostGraphQLSchema( | ||
const schema = await createPostGraphileSchema( | ||
process.env.DATABASE_URL, | ||
@@ -42,3 +43,3 @@ ['users_schema', 'posts_schema'], | ||
```js | ||
const { createPostGraphQLSchema } = require("postgraphile-core"); | ||
const { createPostGraphileSchema } = require("postgraphile-core"); | ||
const { graphql } = require("graphql"); | ||
@@ -49,7 +50,6 @@ const pg = require("pg"); | ||
const pgPool = new pg.Pool({ | ||
connectionString: process.env.DATABASE_URL, | ||
connectionString: process.env.DATABASE_URL | ||
}); | ||
async function runQuery(query, variables) { | ||
// Generate our schema using the default plugins against DATABASE_URL, | ||
@@ -60,9 +60,9 @@ // introspecting the two schemas specified with the options provided. | ||
// application run, not once per query as it is here. | ||
const schema = await createPostGraphQLSchema( | ||
const schema = await createPostGraphileSchema( | ||
process.env.DATABASE_URL, | ||
['users_schema', 'posts_schema'], | ||
["users_schema", "posts_schema"], | ||
{ | ||
dynamicJson: true, | ||
pgJwtSecret: process.env.JWT_SECRET, | ||
pgJwtTypeIdentifier: 'users_schema.jwt_type', | ||
pgJwtTypeIdentifier: "users_schema.jwt_type" | ||
} | ||
@@ -79,6 +79,6 @@ ); | ||
// The following statement is equivalent to (but faster than): | ||
// await pgClient.query("set local role to 'postgraphql_user'"); | ||
// await pgClient.query("set local role to 'postgraphile_user'"); | ||
// await pgClient.query("set local jwt.claims.user_id to '27'"); | ||
await pgClient.query(`select | ||
set_config('role', 'postgraphql_user', true), | ||
set_config('role', 'postgraphile_user', true), | ||
set_config('jwt.claims.user_id', '27', true) | ||
@@ -91,4 +91,4 @@ `); | ||
/* CONTEXT > */ { | ||
pgClient: pgClient, | ||
}, /* < CONTEXT */ | ||
pgClient: pgClient | ||
} /* < CONTEXT */, | ||
variables | ||
@@ -109,9 +109,11 @@ ); | ||
"query MyQuery { allPosts { nodes { id, title, author: userByAuthorId { username } } } }" | ||
).then(result => { | ||
console.dir(result); | ||
pgPool.end(); | ||
}).catch(e => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
) | ||
.then(result => { | ||
console.dir(result); | ||
pgPool.end(); | ||
}) | ||
.catch(e => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
``` | ||
@@ -122,6 +124,6 @@ | ||
To see how this works in a real application, check out | ||
[`withPostGraphQLContext` in | ||
PostGraphQL](https://github.com/postgraphql/postgraphql/blob/master/src/postgraphql/withPostGraphQLContext.ts) | ||
[`withPostGraphileContext` in | ||
PostGraphile](https://github.com/graphile/postgraphile/blob/master/src/postgraphile/withPostGraphileContext.ts) | ||
## `watchPostGraphQLSchema(pgConfig, schemas, options, onNewSchema)` | ||
## `watchPostGraphileSchema(pgConfig, schemas, options, onNewSchema)` | ||
@@ -133,2 +135,2 @@ This function is useful in development; it returns a promise that resolves to a | ||
additional `onNewSchema` option, the options are identical to that of | ||
`createPostGraphQLSchema` above. | ||
`createPostGraphileSchema` above. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46300
262
127
+ Addedgraphile-build@4.0.0-alpha.5(transitive)
+ Addedgraphile-build-pg@4.0.0-alpha.5(transitive)
+ Addedgraphql-parse-resolve-info@4.0.0-alpha.5(transitive)
- Removedgraphile-build@4.0.0-alpha.1(transitive)
- Removedgraphile-build-pg@4.0.0-alpha.4(transitive)
- Removedgraphql-parse-resolve-info@4.0.0-alpha.1(transitive)
Updatedgraphile-build@4.0.0-alpha.5