graphile-query 0.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -1
- package/README.md +153 -27
- package/esm/index.js +64 -0
- package/index.d.ts +36 -0
- package/index.js +70 -0
- package/package.json +26 -58
- package/main/index.js +0 -245
- package/module/index.js +0 -68
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Hyperweb <developers@hyperweb.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,51 +1,177 @@
|
|
|
1
1
|
# graphile-query
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/launchql/launchql/refs/heads/main/assets/outline-logo.svg" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/launchql/launchql/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/launchql/launchql/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/graphile-query"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql?filename=packages%2Fgraphile-query%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## GraphileQuery: Simple GraphQL Execution with PostGraphile Context
|
|
16
|
+
|
|
17
|
+
This module provides utilities to execute GraphQL queries against a PostGraphile-generated schema using PostgreSQL connection pooling and contextual role-based settings.
|
|
18
|
+
|
|
19
|
+
It includes two main classes:
|
|
20
|
+
|
|
21
|
+
* `GraphileQuery`: A flexible query runner that supports `pgSettings`, role-based access control, and custom request context.
|
|
22
|
+
* `GraphileQuerySimple`: A minimal wrapper for GraphQL execution without advanced role or settings logic.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
* Built-in support for PostGraphile context and role-based `pgSettings`
|
|
27
|
+
* Works with pre-built PostGraphile schemas
|
|
28
|
+
* Supports raw string queries or parsed `DocumentNode`s
|
|
29
|
+
* Integrates with PostgreSQL via `pg.Pool`
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
4
34
|
npm install graphile-query
|
|
5
35
|
```
|
|
6
36
|
|
|
7
|
-
##
|
|
37
|
+
## Usage
|
|
8
38
|
|
|
9
|
-
Use as a particular role, skipping any auth logic
|
|
39
|
+
Use as a particular role, skipping any auth logic:
|
|
10
40
|
|
|
11
|
-
```
|
|
41
|
+
```ts
|
|
12
42
|
const results = await client.query({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
role: 'postgres',
|
|
44
|
+
query,
|
|
45
|
+
variables
|
|
16
46
|
});
|
|
17
47
|
```
|
|
18
48
|
|
|
19
|
-
Or pass a request object to be evaluated based on logic
|
|
49
|
+
Or pass a request object to be evaluated based on logic:
|
|
20
50
|
|
|
21
|
-
```
|
|
51
|
+
```ts
|
|
22
52
|
const results = await client.query({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
req: { something: { special: 'e90829ef-1da4-448d-3e44-b3d275702b86' } },
|
|
54
|
+
query: MyGraphQLQuery,
|
|
55
|
+
variables
|
|
26
56
|
});
|
|
27
57
|
```
|
|
28
58
|
|
|
29
|
-
## initialization
|
|
30
59
|
|
|
31
|
-
|
|
32
|
-
import { GraphileQuery, getSchema } from 'graphile-query';
|
|
60
|
+
### 1. Create a GraphQL Schema
|
|
33
61
|
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
```ts
|
|
63
|
+
import { Pool } from 'pg';
|
|
64
|
+
import { getSchema } from 'graphile-query';
|
|
36
65
|
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// custom logic for requests
|
|
42
|
-
return { role: 'public' };
|
|
43
|
-
}
|
|
66
|
+
const pool = new Pool();
|
|
67
|
+
const schema = await getSchema(pool, {
|
|
68
|
+
schema: ['app_public'],
|
|
69
|
+
pgSettings: req => ({ 'myapp.user_id': req.user?.id }),
|
|
44
70
|
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 2. Execute Queries with `GraphileQuery`
|
|
45
74
|
|
|
46
|
-
|
|
47
|
-
|
|
75
|
+
```ts
|
|
76
|
+
import { GraphileQuery } from 'graphile-query';
|
|
48
77
|
|
|
49
|
-
// initialize client
|
|
50
78
|
const client = new GraphileQuery({ schema, pool, settings });
|
|
79
|
+
|
|
80
|
+
const result = await client.query({
|
|
81
|
+
query: `
|
|
82
|
+
query GetUsers {
|
|
83
|
+
allUsers {
|
|
84
|
+
nodes {
|
|
85
|
+
id
|
|
86
|
+
username
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`,
|
|
91
|
+
role: 'authenticated', // optional
|
|
92
|
+
req: { user: { id: 123 } }, // optional
|
|
93
|
+
});
|
|
51
94
|
```
|
|
95
|
+
|
|
96
|
+
### 3. Use `GraphileQuerySimple` for Lightweight Execution
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { GraphileQuerySimple } from 'graphile-query';
|
|
100
|
+
|
|
101
|
+
const client = new GraphileQuerySimple({ schema, pool });
|
|
102
|
+
|
|
103
|
+
const result = await client.query(`
|
|
104
|
+
query {
|
|
105
|
+
currentUser {
|
|
106
|
+
id
|
|
107
|
+
email
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API
|
|
114
|
+
|
|
115
|
+
### `getSchema(pool, settings)`
|
|
116
|
+
|
|
117
|
+
* Builds a PostGraphile schema using the given database pool and settings.
|
|
118
|
+
|
|
119
|
+
### `GraphileQuery`
|
|
120
|
+
|
|
121
|
+
* `constructor({ schema, pool, settings })`
|
|
122
|
+
* `query({ query, variables?, role?, req? })`
|
|
123
|
+
|
|
124
|
+
Supports full context, roles, and settings for advanced scenarios.
|
|
125
|
+
|
|
126
|
+
### `GraphileQuerySimple`
|
|
127
|
+
|
|
128
|
+
* `constructor({ schema, pool })`
|
|
129
|
+
* `query(query, variables?)`
|
|
130
|
+
|
|
131
|
+
Lightweight version with no role or settings support.
|
|
132
|
+
|
|
133
|
+
## Related LaunchQL Tooling
|
|
134
|
+
|
|
135
|
+
### 🧪 Testing
|
|
136
|
+
|
|
137
|
+
* [launchql/pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
138
|
+
* [launchql/graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
139
|
+
* [launchql/pg-query-context](https://github.com/launchql/launchql/tree/main/packages/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
|
|
140
|
+
|
|
141
|
+
### 🧠 Parsing & AST
|
|
142
|
+
|
|
143
|
+
* [launchql/pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
144
|
+
* [launchql/libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
145
|
+
* [launchql/pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
146
|
+
* [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/main/packages/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
147
|
+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
148
|
+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
149
|
+
* [launchql/pg-ast](https://github.com/launchql/launchql/tree/main/packages/pg-ast): **🔍 Low-level AST tools** and transformations for Postgres query structures.
|
|
150
|
+
|
|
151
|
+
### 🚀 API & Dev Tools
|
|
152
|
+
|
|
153
|
+
* [launchql/server](https://github.com/launchql/launchql/tree/main/packages/server): **⚡ Express-based API server** powered by PostGraphile to expose a secure, scalable GraphQL API over your Postgres database.
|
|
154
|
+
* [launchql/explorer](https://github.com/launchql/launchql/tree/main/packages/explorer): **🔎 Visual API explorer** with GraphiQL for browsing across all databases and schemas—useful for debugging, documentation, and API prototyping.
|
|
155
|
+
|
|
156
|
+
### 🔁 Streaming & Uploads
|
|
157
|
+
|
|
158
|
+
* [launchql/s3-streamer](https://github.com/launchql/launchql/tree/main/packages/s3-streamer): **📤 Direct S3 streaming** for large files with support for metadata injection and content validation.
|
|
159
|
+
* [launchql/etag-hash](https://github.com/launchql/launchql/tree/main/packages/etag-hash): **🏷️ S3-compatible ETags** created by streaming and hashing file uploads in chunks.
|
|
160
|
+
* [launchql/etag-stream](https://github.com/launchql/launchql/tree/main/packages/etag-stream): **🔄 ETag computation** via Node stream transformer during upload or transfer.
|
|
161
|
+
* [launchql/uuid-hash](https://github.com/launchql/launchql/tree/main/packages/uuid-hash): **🆔 Deterministic UUIDs** generated from hashed content, great for deduplication and asset referencing.
|
|
162
|
+
* [launchql/uuid-stream](https://github.com/launchql/launchql/tree/main/packages/uuid-stream): **🌊 Streaming UUID generation** based on piped file content—ideal for upload pipelines.
|
|
163
|
+
* [launchql/upload-names](https://github.com/launchql/launchql/tree/main/packages/upload-names): **📂 Collision-resistant filenames** utility for structured and unique file names for uploads.
|
|
164
|
+
|
|
165
|
+
### 🧰 CLI & Codegen
|
|
166
|
+
|
|
167
|
+
* [@launchql/cli](https://github.com/launchql/launchql/tree/main/packages/cli): **🖥️ Command-line toolkit** for managing LaunchQL projects—supports database scaffolding, migrations, seeding, code generation, and automation.
|
|
168
|
+
* [launchql/launchql-gen](https://github.com/launchql/launchql/tree/main/packages/launchql-gen): **✨ Auto-generated GraphQL** mutations and queries dynamically built from introspected schema data.
|
|
169
|
+
* [@launchql/query-builder](https://github.com/launchql/launchql/tree/main/packages/query-builder): **🏗️ SQL constructor** providing a robust TypeScript-based query builder for dynamic generation of `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and stored procedure calls—supports advanced SQL features like `JOIN`, `GROUP BY`, and schema-qualified queries.
|
|
170
|
+
* [@launchql/query](https://github.com/launchql/launchql/tree/main/packages/query): **🧩 Fluent GraphQL builder** for PostGraphile schemas. ⚡ Schema-aware via introspection, 🧩 composable and ergonomic for building deeply nested queries.
|
|
171
|
+
|
|
172
|
+
## Disclaimer
|
|
173
|
+
|
|
174
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
175
|
+
|
|
176
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
177
|
+
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { withPostGraphileContext, createPostGraphileSchema } from 'postgraphile';
|
|
2
|
+
import { graphql } from 'graphql';
|
|
3
|
+
import { print } from 'graphql/language/printer';
|
|
4
|
+
export const getSchema = async (pool, settings) => await createPostGraphileSchema(pool, settings.schema, settings);
|
|
5
|
+
export class GraphileQuery {
|
|
6
|
+
pool;
|
|
7
|
+
schema;
|
|
8
|
+
settings;
|
|
9
|
+
constructor({ schema, pool, settings }) {
|
|
10
|
+
if (!schema)
|
|
11
|
+
throw new Error('requires a schema');
|
|
12
|
+
if (!pool)
|
|
13
|
+
throw new Error('requires a pool');
|
|
14
|
+
if (!settings)
|
|
15
|
+
throw new Error('requires graphile settings');
|
|
16
|
+
this.pool = pool;
|
|
17
|
+
this.schema = schema;
|
|
18
|
+
this.settings = settings;
|
|
19
|
+
}
|
|
20
|
+
async query({ req = {}, query, variables, role }) {
|
|
21
|
+
const queryString = typeof query === 'string' ? query : print(query);
|
|
22
|
+
const { pgSettings: pgSettingsGenerator } = this.settings;
|
|
23
|
+
const pgSettings = role != null
|
|
24
|
+
? { role }
|
|
25
|
+
: typeof pgSettingsGenerator === 'function'
|
|
26
|
+
? await pgSettingsGenerator(req)
|
|
27
|
+
: pgSettingsGenerator;
|
|
28
|
+
return await withPostGraphileContext({
|
|
29
|
+
...this.settings,
|
|
30
|
+
pgPool: this.pool,
|
|
31
|
+
pgSettings
|
|
32
|
+
}, async (context) => {
|
|
33
|
+
return await graphql({
|
|
34
|
+
schema: this.schema,
|
|
35
|
+
source: queryString,
|
|
36
|
+
contextValue: context,
|
|
37
|
+
variableValues: variables
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class GraphileQuerySimple {
|
|
43
|
+
pool;
|
|
44
|
+
schema;
|
|
45
|
+
constructor({ schema, pool }) {
|
|
46
|
+
if (!schema)
|
|
47
|
+
throw new Error('requires a schema');
|
|
48
|
+
if (!pool)
|
|
49
|
+
throw new Error('requires a pool');
|
|
50
|
+
this.pool = pool;
|
|
51
|
+
this.schema = schema;
|
|
52
|
+
}
|
|
53
|
+
async query(query, variables) {
|
|
54
|
+
const queryString = typeof query === 'string' ? query : print(query);
|
|
55
|
+
return await withPostGraphileContext({ pgPool: this.pool }, async (context) => {
|
|
56
|
+
return await graphql({
|
|
57
|
+
schema: this.schema,
|
|
58
|
+
source: queryString,
|
|
59
|
+
contextValue: context,
|
|
60
|
+
variableValues: variables
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PostGraphileOptions } from 'postgraphile';
|
|
2
|
+
import { GraphQLSchema, ExecutionResult } from 'graphql';
|
|
3
|
+
import { Pool } from 'pg';
|
|
4
|
+
interface GraphileSettings extends PostGraphileOptions {
|
|
5
|
+
schema: string | string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const getSchema: (pool: Pool, settings: GraphileSettings) => Promise<GraphQLSchema>;
|
|
8
|
+
interface GraphileQueryParams {
|
|
9
|
+
schema: GraphQLSchema;
|
|
10
|
+
pool: Pool;
|
|
11
|
+
settings: GraphileSettings;
|
|
12
|
+
}
|
|
13
|
+
interface QueryOptions {
|
|
14
|
+
req?: any;
|
|
15
|
+
query: string;
|
|
16
|
+
variables?: Record<string, any>;
|
|
17
|
+
role?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class GraphileQuery {
|
|
20
|
+
private pool;
|
|
21
|
+
private schema;
|
|
22
|
+
private settings;
|
|
23
|
+
constructor({ schema, pool, settings }: GraphileQueryParams);
|
|
24
|
+
query({ req, query, variables, role }: QueryOptions): Promise<ExecutionResult>;
|
|
25
|
+
}
|
|
26
|
+
interface GraphileQuerySimpleParams {
|
|
27
|
+
schema: GraphQLSchema;
|
|
28
|
+
pool: Pool;
|
|
29
|
+
}
|
|
30
|
+
export declare class GraphileQuerySimple {
|
|
31
|
+
private pool;
|
|
32
|
+
private schema;
|
|
33
|
+
constructor({ schema, pool }: GraphileQuerySimpleParams);
|
|
34
|
+
query(query: string, variables?: Record<string, any>): Promise<ExecutionResult>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphileQuerySimple = exports.GraphileQuery = exports.getSchema = void 0;
|
|
4
|
+
const postgraphile_1 = require("postgraphile");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
const printer_1 = require("graphql/language/printer");
|
|
7
|
+
const getSchema = async (pool, settings) => await (0, postgraphile_1.createPostGraphileSchema)(pool, settings.schema, settings);
|
|
8
|
+
exports.getSchema = getSchema;
|
|
9
|
+
class GraphileQuery {
|
|
10
|
+
pool;
|
|
11
|
+
schema;
|
|
12
|
+
settings;
|
|
13
|
+
constructor({ schema, pool, settings }) {
|
|
14
|
+
if (!schema)
|
|
15
|
+
throw new Error('requires a schema');
|
|
16
|
+
if (!pool)
|
|
17
|
+
throw new Error('requires a pool');
|
|
18
|
+
if (!settings)
|
|
19
|
+
throw new Error('requires graphile settings');
|
|
20
|
+
this.pool = pool;
|
|
21
|
+
this.schema = schema;
|
|
22
|
+
this.settings = settings;
|
|
23
|
+
}
|
|
24
|
+
async query({ req = {}, query, variables, role }) {
|
|
25
|
+
const queryString = typeof query === 'string' ? query : (0, printer_1.print)(query);
|
|
26
|
+
const { pgSettings: pgSettingsGenerator } = this.settings;
|
|
27
|
+
const pgSettings = role != null
|
|
28
|
+
? { role }
|
|
29
|
+
: typeof pgSettingsGenerator === 'function'
|
|
30
|
+
? await pgSettingsGenerator(req)
|
|
31
|
+
: pgSettingsGenerator;
|
|
32
|
+
return await (0, postgraphile_1.withPostGraphileContext)({
|
|
33
|
+
...this.settings,
|
|
34
|
+
pgPool: this.pool,
|
|
35
|
+
pgSettings
|
|
36
|
+
}, async (context) => {
|
|
37
|
+
return await (0, graphql_1.graphql)({
|
|
38
|
+
schema: this.schema,
|
|
39
|
+
source: queryString,
|
|
40
|
+
contextValue: context,
|
|
41
|
+
variableValues: variables
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.GraphileQuery = GraphileQuery;
|
|
47
|
+
class GraphileQuerySimple {
|
|
48
|
+
pool;
|
|
49
|
+
schema;
|
|
50
|
+
constructor({ schema, pool }) {
|
|
51
|
+
if (!schema)
|
|
52
|
+
throw new Error('requires a schema');
|
|
53
|
+
if (!pool)
|
|
54
|
+
throw new Error('requires a pool');
|
|
55
|
+
this.pool = pool;
|
|
56
|
+
this.schema = schema;
|
|
57
|
+
}
|
|
58
|
+
async query(query, variables) {
|
|
59
|
+
const queryString = typeof query === 'string' ? query : (0, printer_1.print)(query);
|
|
60
|
+
return await (0, postgraphile_1.withPostGraphileContext)({ pgPool: this.pool }, async (context) => {
|
|
61
|
+
return await (0, graphql_1.graphql)({
|
|
62
|
+
schema: this.schema,
|
|
63
|
+
source: queryString,
|
|
64
|
+
contextValue: context,
|
|
65
|
+
variableValues: variables
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.GraphileQuerySimple = GraphileQuerySimple;
|
package/package.json
CHANGED
|
@@ -1,70 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-query",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "query graphile schemas",
|
|
3
|
+
"version": "2.1.5",
|
|
5
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"test": "__tests__"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"main",
|
|
16
|
-
"module"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start",
|
|
20
|
-
"build:module": "cross-env MODULE=true babel src --out-dir module --delete-dir-on-start",
|
|
21
|
-
"build": "npm run build:module && npm run build:main",
|
|
22
|
-
"prepublish": "npm run build",
|
|
23
|
-
"dev": "cross-env NODE_ENV=development babel-node src/index",
|
|
24
|
-
"watch": "cross-env NODE_ENV=development babel-watch src/index",
|
|
25
|
-
"lint": "eslint src --fix",
|
|
26
|
-
"test": "jest",
|
|
27
|
-
"test:watch": "jest --watch",
|
|
28
|
-
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
29
|
-
},
|
|
5
|
+
"description": "graphile query",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
10
|
+
"license": "MIT",
|
|
30
11
|
"publishConfig": {
|
|
31
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
32
14
|
},
|
|
33
15
|
"repository": {
|
|
34
16
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/launchql/launchql"
|
|
36
18
|
},
|
|
37
|
-
"keywords": [],
|
|
38
19
|
"bugs": {
|
|
39
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/launchql/launchql/issues"
|
|
40
21
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"babel-core": "7.0.0-bridge.0",
|
|
51
|
-
"babel-eslint": "10.1.0",
|
|
52
|
-
"babel-jest": "25.1.0",
|
|
53
|
-
"babel-watch": "^7.0.0",
|
|
54
|
-
"cross-env": "^7.0.2",
|
|
55
|
-
"eslint": "6.8.0",
|
|
56
|
-
"eslint-config-prettier": "^6.10.0",
|
|
57
|
-
"eslint-plugin-prettier": "^3.1.2",
|
|
58
|
-
"jest": "^24.5.0",
|
|
59
|
-
"jest-in-case": "^1.0.2",
|
|
60
|
-
"prettier": "^2.1.2",
|
|
61
|
-
"regenerator-runtime": "^0.13.7"
|
|
62
|
-
},
|
|
63
|
-
"peerDependencies": {
|
|
64
|
-
"postgraphile": "4.x"
|
|
22
|
+
"scripts": {
|
|
23
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
24
|
+
"clean": "rimraf dist/**",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
|
|
27
|
+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
28
|
+
"lint": "eslint . --fix",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch"
|
|
65
31
|
},
|
|
66
32
|
"dependencies": {
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
}
|
|
33
|
+
"graphql": "15.5.2",
|
|
34
|
+
"pg": "^8.16.0",
|
|
35
|
+
"postgraphile": "^4.14.1"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "8a638ef47a175c964a63431017d83587e62efbb8"
|
|
38
|
+
}
|
package/main/index.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.GraphileQuerySimple = exports.GraphileQuery = exports.getSchema = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
|
-
|
|
18
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
19
|
-
|
|
20
|
-
var _postgraphile = require("postgraphile");
|
|
21
|
-
|
|
22
|
-
var _graphql = require("graphql");
|
|
23
|
-
|
|
24
|
-
var _printer = require("graphql/language/printer");
|
|
25
|
-
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
|
|
28
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
29
|
-
|
|
30
|
-
var getSchema = /*#__PURE__*/function () {
|
|
31
|
-
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pool, settings) {
|
|
32
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
33
|
-
while (1) {
|
|
34
|
-
switch (_context.prev = _context.next) {
|
|
35
|
-
case 0:
|
|
36
|
-
_context.next = 2;
|
|
37
|
-
return (0, _postgraphile.createPostGraphileSchema)(pool, settings.schema, settings);
|
|
38
|
-
|
|
39
|
-
case 2:
|
|
40
|
-
return _context.abrupt("return", _context.sent);
|
|
41
|
-
|
|
42
|
-
case 3:
|
|
43
|
-
case "end":
|
|
44
|
-
return _context.stop();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}, _callee);
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
return function getSchema(_x, _x2) {
|
|
51
|
-
return _ref.apply(this, arguments);
|
|
52
|
-
};
|
|
53
|
-
}();
|
|
54
|
-
|
|
55
|
-
exports.getSchema = getSchema;
|
|
56
|
-
|
|
57
|
-
var GraphileQuery = /*#__PURE__*/function () {
|
|
58
|
-
function GraphileQuery(_ref2) {
|
|
59
|
-
var schema = _ref2.schema,
|
|
60
|
-
pool = _ref2.pool,
|
|
61
|
-
settings = _ref2.settings;
|
|
62
|
-
(0, _classCallCheck2["default"])(this, GraphileQuery);
|
|
63
|
-
if (!schema) throw new Error('requires a schema');
|
|
64
|
-
if (!pool) throw new Error('requires a pool');
|
|
65
|
-
if (!settings) throw new Error('requires graphile settings');
|
|
66
|
-
this.pool = pool;
|
|
67
|
-
this.schema = schema;
|
|
68
|
-
this.settings = settings;
|
|
69
|
-
} // role is optional! it overrides anything from req passed in.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(0, _createClass2["default"])(GraphileQuery, [{
|
|
73
|
-
key: "query",
|
|
74
|
-
value: function () {
|
|
75
|
-
var _query2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(_ref3) {
|
|
76
|
-
var _this = this;
|
|
77
|
-
|
|
78
|
-
var _ref3$req, req, _query, variables, role, queryString, pgSettingsGenerator, pgSettings;
|
|
79
|
-
|
|
80
|
-
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
81
|
-
while (1) {
|
|
82
|
-
switch (_context3.prev = _context3.next) {
|
|
83
|
-
case 0:
|
|
84
|
-
_ref3$req = _ref3.req, req = _ref3$req === void 0 ? {} : _ref3$req, _query = _ref3.query, variables = _ref3.variables, role = _ref3.role;
|
|
85
|
-
queryString = typeof _query === 'string' ? _query : (0, _printer.print)(_query);
|
|
86
|
-
pgSettingsGenerator = this.settings.pgSettings;
|
|
87
|
-
|
|
88
|
-
if (!role) {
|
|
89
|
-
_context3.next = 7;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_context3.t0 = {
|
|
94
|
-
role: role
|
|
95
|
-
};
|
|
96
|
-
_context3.next = 15;
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
case 7:
|
|
100
|
-
if (!(typeof pgSettingsGenerator === 'function')) {
|
|
101
|
-
_context3.next = 13;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_context3.next = 10;
|
|
106
|
-
return pgSettingsGenerator(req);
|
|
107
|
-
|
|
108
|
-
case 10:
|
|
109
|
-
_context3.t1 = _context3.sent;
|
|
110
|
-
_context3.next = 14;
|
|
111
|
-
break;
|
|
112
|
-
|
|
113
|
-
case 13:
|
|
114
|
-
_context3.t1 = pgSettingsGenerator;
|
|
115
|
-
|
|
116
|
-
case 14:
|
|
117
|
-
_context3.t0 = _context3.t1;
|
|
118
|
-
|
|
119
|
-
case 15:
|
|
120
|
-
pgSettings = _context3.t0;
|
|
121
|
-
_context3.next = 18;
|
|
122
|
-
return (0, _postgraphile.withPostGraphileContext)(_objectSpread(_objectSpread({}, this.settings), {}, {
|
|
123
|
-
pgPool: this.pool,
|
|
124
|
-
pgSettings: pgSettings
|
|
125
|
-
}), /*#__PURE__*/function () {
|
|
126
|
-
var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(context) {
|
|
127
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
128
|
-
while (1) {
|
|
129
|
-
switch (_context2.prev = _context2.next) {
|
|
130
|
-
case 0:
|
|
131
|
-
_context2.next = 2;
|
|
132
|
-
return (0, _graphql.graphql)(_this.schema, queryString, null, _objectSpread({}, context), variables);
|
|
133
|
-
|
|
134
|
-
case 2:
|
|
135
|
-
return _context2.abrupt("return", _context2.sent);
|
|
136
|
-
|
|
137
|
-
case 3:
|
|
138
|
-
case "end":
|
|
139
|
-
return _context2.stop();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}, _callee2);
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
return function (_x4) {
|
|
146
|
-
return _ref4.apply(this, arguments);
|
|
147
|
-
};
|
|
148
|
-
}());
|
|
149
|
-
|
|
150
|
-
case 18:
|
|
151
|
-
return _context3.abrupt("return", _context3.sent);
|
|
152
|
-
|
|
153
|
-
case 19:
|
|
154
|
-
case "end":
|
|
155
|
-
return _context3.stop();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}, _callee3, this);
|
|
159
|
-
}));
|
|
160
|
-
|
|
161
|
-
function query(_x3) {
|
|
162
|
-
return _query2.apply(this, arguments);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return query;
|
|
166
|
-
}()
|
|
167
|
-
}]);
|
|
168
|
-
return GraphileQuery;
|
|
169
|
-
}();
|
|
170
|
-
|
|
171
|
-
exports.GraphileQuery = GraphileQuery;
|
|
172
|
-
|
|
173
|
-
var GraphileQuerySimple = /*#__PURE__*/function () {
|
|
174
|
-
function GraphileQuerySimple(_ref5) {
|
|
175
|
-
var schema = _ref5.schema,
|
|
176
|
-
pool = _ref5.pool;
|
|
177
|
-
(0, _classCallCheck2["default"])(this, GraphileQuerySimple);
|
|
178
|
-
if (!schema) throw new Error('requires a schema');
|
|
179
|
-
if (!pool) throw new Error('requires a pool');
|
|
180
|
-
this.pool = pool;
|
|
181
|
-
this.schema = schema;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
(0, _createClass2["default"])(GraphileQuerySimple, [{
|
|
185
|
-
key: "query",
|
|
186
|
-
value: function () {
|
|
187
|
-
var _query4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_query3, variables) {
|
|
188
|
-
var _this2 = this;
|
|
189
|
-
|
|
190
|
-
var queryString;
|
|
191
|
-
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
192
|
-
while (1) {
|
|
193
|
-
switch (_context5.prev = _context5.next) {
|
|
194
|
-
case 0:
|
|
195
|
-
queryString = typeof _query3 === 'string' ? _query3 : (0, _printer.print)(_query3);
|
|
196
|
-
_context5.next = 3;
|
|
197
|
-
return (0, _postgraphile.withPostGraphileContext)({
|
|
198
|
-
pgPool: this.pool
|
|
199
|
-
}, /*#__PURE__*/function () {
|
|
200
|
-
var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(context) {
|
|
201
|
-
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
202
|
-
while (1) {
|
|
203
|
-
switch (_context4.prev = _context4.next) {
|
|
204
|
-
case 0:
|
|
205
|
-
_context4.next = 2;
|
|
206
|
-
return (0, _graphql.graphql)(_this2.schema, queryString, null, _objectSpread({}, context), variables);
|
|
207
|
-
|
|
208
|
-
case 2:
|
|
209
|
-
return _context4.abrupt("return", _context4.sent);
|
|
210
|
-
|
|
211
|
-
case 3:
|
|
212
|
-
case "end":
|
|
213
|
-
return _context4.stop();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}, _callee4);
|
|
217
|
-
}));
|
|
218
|
-
|
|
219
|
-
return function (_x7) {
|
|
220
|
-
return _ref6.apply(this, arguments);
|
|
221
|
-
};
|
|
222
|
-
}());
|
|
223
|
-
|
|
224
|
-
case 3:
|
|
225
|
-
return _context5.abrupt("return", _context5.sent);
|
|
226
|
-
|
|
227
|
-
case 4:
|
|
228
|
-
case "end":
|
|
229
|
-
return _context5.stop();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, _callee5, this);
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
function query(_x5, _x6) {
|
|
236
|
-
return _query4.apply(this, arguments);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return query;
|
|
240
|
-
}()
|
|
241
|
-
}]);
|
|
242
|
-
return GraphileQuerySimple;
|
|
243
|
-
}();
|
|
244
|
-
|
|
245
|
-
exports.GraphileQuerySimple = GraphileQuerySimple;
|
package/module/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
|
-
import { withPostGraphileContext, createPostGraphileSchema } from 'postgraphile';
|
|
8
|
-
import { graphql } from 'graphql';
|
|
9
|
-
import { print } from 'graphql/language/printer';
|
|
10
|
-
export const getSchema = async (pool, settings) => await createPostGraphileSchema(pool, settings.schema, settings);
|
|
11
|
-
export class GraphileQuery {
|
|
12
|
-
constructor({
|
|
13
|
-
schema,
|
|
14
|
-
pool,
|
|
15
|
-
settings
|
|
16
|
-
}) {
|
|
17
|
-
if (!schema) throw new Error('requires a schema');
|
|
18
|
-
if (!pool) throw new Error('requires a pool');
|
|
19
|
-
if (!settings) throw new Error('requires graphile settings');
|
|
20
|
-
this.pool = pool;
|
|
21
|
-
this.schema = schema;
|
|
22
|
-
this.settings = settings;
|
|
23
|
-
} // role is optional! it overrides anything from req passed in.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async query({
|
|
27
|
-
req = {},
|
|
28
|
-
query,
|
|
29
|
-
variables,
|
|
30
|
-
role
|
|
31
|
-
}) {
|
|
32
|
-
const queryString = typeof query === 'string' ? query : print(query);
|
|
33
|
-
const {
|
|
34
|
-
pgSettings: pgSettingsGenerator
|
|
35
|
-
} = this.settings;
|
|
36
|
-
const pgSettings = role ? {
|
|
37
|
-
role
|
|
38
|
-
} : typeof pgSettingsGenerator === 'function' ? await pgSettingsGenerator(req) : pgSettingsGenerator;
|
|
39
|
-
return await withPostGraphileContext(_objectSpread(_objectSpread({}, this.settings), {}, {
|
|
40
|
-
pgPool: this.pool,
|
|
41
|
-
pgSettings
|
|
42
|
-
}), async context => {
|
|
43
|
-
return await graphql(this.schema, queryString, null, _objectSpread({}, context), variables);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
export class GraphileQuerySimple {
|
|
49
|
-
constructor({
|
|
50
|
-
schema,
|
|
51
|
-
pool
|
|
52
|
-
}) {
|
|
53
|
-
if (!schema) throw new Error('requires a schema');
|
|
54
|
-
if (!pool) throw new Error('requires a pool');
|
|
55
|
-
this.pool = pool;
|
|
56
|
-
this.schema = schema;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async query(query, variables) {
|
|
60
|
-
const queryString = typeof query === 'string' ? query : print(query);
|
|
61
|
-
return await withPostGraphileContext({
|
|
62
|
-
pgPool: this.pool
|
|
63
|
-
}, async context => {
|
|
64
|
-
return await graphql(this.schema, queryString, null, _objectSpread({}, context), variables);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|