Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tabWidth": 2,
"semi": true,
"useTabs": false,
"singleQuote": false
"singleQuote": true,
"jsxSingleQuote": false
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
"resolutions": {
"pg": "^8.16.0",
"@types/pg": "^8.15.2",
"graphql": "15.5.2"
"graphql": "15.10.1",
"graphql-upload": "^13.0.0"
},
"overrides": {
"graphql": "15.5.2",
"graphql": "15.10.1",
"graphql-upload": "^13.0.0",
"@pyramation/postgis": "0.1.1"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"shelljs": "^0.9.2"
},
"resolutions": {
"graphql": "15.5.2"
"graphql": "15.10.1"
},
"keywords": [
"cli",
Expand Down
6 changes: 3 additions & 3 deletions packages/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"devDependencies": {
"@types/express": "^5.0.1",
"@types/graphql-upload": "^15.0.2",
"@types/graphql-upload": "^8.0.12",
"@types/rimraf": "^4.0.5",
"nodemon": "^3.1.10",
"ts-node": "^10.9.2"
Expand All @@ -64,6 +64,6 @@
"interface"
],
"resolutions": {
"graphql": "15.5.2"
"graphql": "15.10.1"
}
}
}
63 changes: 32 additions & 31 deletions packages/explorer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import {
cors,
healthz,
poweredBy,
} from '@launchql/server-utils';
import { LaunchQLOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/env';
import { cors, healthz, poweredBy } from '@launchql/server-utils';
import { LaunchQLOptions } from '@launchql/types';
import { middleware as parseDomains } from '@launchql/url-domains';
import express, { Express,NextFunction, Request, Response } from 'express';
import express, { Express, NextFunction, Request, Response } from 'express';
import { GraphileCache, graphileCache } from 'graphile-cache';
import graphqlUploadExpress from 'graphql-upload/public/graphqlUploadExpress.js';
import graphqlUpload from 'graphql-upload';
// Scalar
import { getPgPool } from 'pg-cache';
import { getPgEnvOptions } from 'pg-env';
import { postgraphile } from 'postgraphile';

import { printDatabases,printSchemas } from './render';
import { printDatabases, printSchemas } from './render';
import { getGraphileSettings } from './settings';

export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
const opts = getEnvOptions(rawOpts);

const {
pg,
server
} = opts;
const { pg, server } = opts;

const getGraphileInstanceObj = (dbname: string, schemaname: string): GraphileCache => {
const getGraphileInstanceObj = (
dbname: string,
schemaname: string
): GraphileCache => {
const key = `${dbname}.${schemaname}`;

if (graphileCache.has(key)) {
Expand All @@ -34,24 +31,25 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
const settings = {
...getGraphileSettings({
...opts,
graphile: { schema: schemaname }
graphile: { schema: schemaname },
}),
graphqlRoute: '/graphql',
graphiqlRoute: '/graphiql'
graphiqlRoute: '/graphiql',
};

const pgPool = getPgPool(
getPgEnvOptions({
...opts.pg,
database: dbname
}));
database: dbname,
})
);

const handler = postgraphile(pgPool, schemaname, settings);

const obj = {
pgPool,
pgPoolKey: dbname,
handler
handler,
};

graphileCache.set(key, obj);
Expand All @@ -64,7 +62,7 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
cors(app, server.origin);
app.use(parseDomains());
app.use(poweredBy('launchql'));
app.use(graphqlUploadExpress());
app.use(graphqlUpload.graphqlUploadExpress());

app.use(async (req: Request, res: Response, next: NextFunction) => {
if (req.urlDomains?.subdomains.length === 1) {
Expand All @@ -73,9 +71,10 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
const pgPool = getPgPool(
getPgEnvOptions({
...opts.pg,
database: dbName
}));

database: dbName,
})
);

const results = await pgPool.query(`
SELECT s.nspname AS table_schema
FROM pg_catalog.pg_namespace s
Expand All @@ -87,7 +86,7 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
schemas: results.rows,
req,
hostname: server.host,
port: server.port
port: server.port,
})
);
return;
Expand All @@ -108,15 +107,14 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
if (req.urlDomains?.subdomains.length === 2) {
const [, dbName] = req.urlDomains.subdomains;
try {

const pgPool = getPgPool(
getPgEnvOptions({
...opts.pg,
database: dbName
}));
database: dbName,
})
);

await pgPool.query('SELECT 1;');

} catch (e: any) {
if (e.message?.match(/does not exist/)) {
res.status(404).send('DB Not found');
Expand Down Expand Up @@ -162,14 +160,17 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
const rootPgPool = getPgPool(
getPgEnvOptions({
...opts.pg,
database: opts.pg.user // is this to get postgres?
}));
database: opts.pg.user, // is this to get postgres?
})
);

const results = await rootPgPool.query(`
SELECT * FROM pg_catalog.pg_database
WHERE datistemplate = FALSE AND datname != 'postgres' AND datname !~ '^pg_'
`);
res.send(printDatabases({ databases: results.rows, req, port: server.port }));
res.send(
printDatabases({ databases: results.rows, req, port: server.port })
);
return;
} catch (e: any) {
if (e.message?.match(/does not exist/)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gql-ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"test:watch": "jest --watch"
},
"dependencies": {
"graphql": "15.5.2"
"graphql": "15.10.1"
},
"keywords": [
"graphql",
Expand Down
4 changes: 2 additions & 2 deletions packages/graphile-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"test:watch": "jest --watch"
},
"dependencies": {
"graphql": "15.5.2",
"graphql": "15.10.1",
"pg": "^8.16.0",
"postgraphile": "^4.14.1"
},
"resolutions": {
"graphql": "15.5.2"
"graphql": "15.10.1"
},
"keywords": [
"graphql",
Expand Down
5 changes: 3 additions & 2 deletions packages/graphile-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"postgraphile-derived-upload-field": "^0.0.6",
"postgraphile-plugin-connection-filter": "^2.3.0",
"postgraphile-plugin-connection-filter-postgis": "^1.0.0-alpha.6",
"graphql-upload": "^13.0.0",
"request-ip": "^3.3.0"
},
"devDependencies": {
Expand All @@ -65,7 +66,7 @@
"ts-node": "^10.9.2"
},
"resolutions": {
"graphql": "15.5.2"
"graphql": "15.10.1"
},
"keywords": [
"graphile",
Expand All @@ -74,4 +75,4 @@
"launchql",
"graphql"
]
}
}
40 changes: 18 additions & 22 deletions packages/graphile-settings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import PgManyToMany from '@graphile-contrib/pg-many-to-many';
import { LaunchQLOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/env';
import { LaunchQLOptions } from '@launchql/types';
import PgPostgis from '@pyramation/postgis';
// @ts-ignore
import FulltextFilterPlugin from '@pyramation/postgraphile-plugin-fulltext-filter';
import { NodePlugin, Plugin } from 'graphile-build';
import {
additionalGraphQLContextFromRequest as langAdditional,
LangPlugin
LangPlugin,
// @ts-ignore
} from 'graphile-i18n';
// @ts-ignore
Expand All @@ -17,32 +17,28 @@ import PgSearch from 'graphile-search-plugin';
// @ts-ignore
import PgSimpleInflector from 'graphile-simple-inflector';
import { PostGraphileOptions } from 'postgraphile';
// @ts-ignore
import PostGraphileUploadFieldPlugin from 'postgraphile-derived-upload-field';
import ConnectionFilterPlugin from 'postgraphile-plugin-connection-filter';
// @ts-ignore
import PgPostgisFilter from 'postgraphile-plugin-connection-filter-postgis';

import LqlTypesPlugin from './plugins/types';
import UploadPostGraphilePlugin from './plugins/upload-postgraphile-plugin';
import { Uploader } from './resolvers/upload';

export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptions => {
export const getGraphileSettings = (
rawOpts: LaunchQLOptions
): PostGraphileOptions => {
const opts = getEnvOptions(rawOpts);

const {
server,
graphile,
features,
cdn
} = opts;
const { server, graphile, features, cdn } = opts;

// Instantiate uploader with merged cdn opts
const uploader = new Uploader({
bucketName: cdn.bucketName!,
awsRegion: cdn.awsRegion!,
awsAccessKey: cdn.awsAccessKey!,
awsSecretKey: cdn.awsSecretKey!,
minioEndpoint: cdn.minioEndpoint
minioEndpoint: cdn.minioEndpoint,
});

const resolveUpload = uploader.resolveUpload.bind(uploader);
Expand All @@ -51,10 +47,10 @@ export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptio
ConnectionFilterPlugin,
FulltextFilterPlugin,
LqlTypesPlugin,
PostGraphileUploadFieldPlugin,
UploadPostGraphilePlugin,
PgMetaschema,
PgManyToMany,
PgSearch
PgSearch,
];

if (features?.postgis) {
Expand All @@ -74,27 +70,27 @@ export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptio
name: 'upload',
namespaceName: 'public',
type: 'JSON',
resolve: resolveUpload
resolve: resolveUpload,
},
{
name: 'attachment',
namespaceName: 'public',
type: 'String',
resolve: resolveUpload
resolve: resolveUpload,
},
{
name: 'image',
namespaceName: 'public',
type: 'JSON',
resolve: resolveUpload
resolve: resolveUpload,
},
{
tag: 'upload',
resolve: resolveUpload
}
resolve: resolveUpload,
},
],
pgSimplifyOppositeBaseNames: features?.oppositeBaseNames,
connectionFilterComputedColumns: false
connectionFilterComputedColumns: false,
},
appendPlugins: plugins,
skipPlugins: [NodePlugin],
Expand All @@ -121,7 +117,7 @@ export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptio
additionalGraphQLContextFromRequest: (req, res) => ({
...langAdditional(req, res),
req,
res
})
res,
}),
};
};
Loading