Skip to content

Commit

Permalink
Auto-complete of plugin names in preset (#2155)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Aug 16, 2024
2 parents 1b7fcbf + 792988e commit 54c9027
Show file tree
Hide file tree
Showing 76 changed files with 534 additions and 15 deletions.
10 changes: 10 additions & 0 deletions .changeset/two-balloons-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"graphile-build-pg": patch
"graphile-build": patch
"postgraphile": patch
"graphile-config": patch
---

`disablePlugins` now supports TypeScript auto-completion of known plugin names.
Other names are still accepted without error, so this is just a minor DX
improvement rather than type safety.
8 changes: 8 additions & 0 deletions grafast/dataplan-pg/src/plugins/PgContextPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export const EMPTY_OBJECT: Record<string, never> = Object.freeze(
Object.create(null),
);

declare global {
namespace GraphileConfig {
interface Plugins {
PgContextPlugin: true;
}
}
}

export const PgContextPlugin: GraphileConfig.Plugin = {
name: "PgContextPlugin",
description:
Expand Down
8 changes: 8 additions & 0 deletions grafast/grafserv-persisted/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import LRU from "@graphile/lru";
import type { PersistedOperationGetter } from "./interfaces.js";
import { version } from "./version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PersistedPlugin: true;
}
}
}

const PersistedPlugin: GraphileConfig.Plugin = {
name: "PersistedPlugin",
description: "Enables persisted operations in Grafserv",
Expand Down
8 changes: 8 additions & 0 deletions grafast/grafserv/src/envelop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ declare global {
}
}

declare global {
namespace GraphileConfig {
interface Plugins {
GrafservEnvelopPlugin: true;
}
}
}

export const GrafservEnvelopPlugin: GraphileConfig.Plugin = {
name: "GrafservEnvelopPlugin",
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ const pool = new Pool({
});
const withPgClient: WithPgClient = makePgAdaptorWithPgClient(pool);

declare global {
namespace GraphileConfig {
interface Plugins {
UseRelationNamesPlugin: true;
}
}
}

async function main() {
// Create our GraphQL schema by applying all the plugins
const executor = EXPORTABLE(
Expand Down
8 changes: 8 additions & 0 deletions graphile-build/graphile-build-pg/src/examples/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export function getPool() {
return pool;
}

declare global {
namespace GraphileConfig {
interface Plugins {
EnumManglingPlugin: true;
}
}
}

const EnumManglingPlugin: GraphileConfig.Plugin = {
name: "EnumManglingPlugin",
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { tagToString } from "../utils.js";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgAllRowsPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import "graphile-config";

import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgAttributeDeprecationPlugin: true;
}
}
}

export const PgAttributeDeprecationPlugin: GraphileConfig.Plugin = {
name: "PgAttributeDeprecationPlugin",
description: "Marks a attribute as deprecated if it has the deprecated tag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgAttributesPlugin: true;
}
}

namespace GraphileBuild {
interface Build {
pgResolveOutputType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import { getCodecMetaLookupFromInput, makePgCodecMeta } from "../inputUtils.js";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgBasicsPlugin: true;
}
}

namespace GraphileBuild {
interface BuildVersions {
"graphile-build-pg": string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ declare global {
}

namespace GraphileConfig {
interface Plugins {
PgCodecsPlugin: true;
}

interface Provides {
PgCodecs: true;
}

interface GatherHelpers {
pgCodecs: {
getCodecFromClass(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import type { GraphQLInputObjectType } from "grafast/graphql";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgConditionArgumentPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
conditionType(this: Inflection, typeName: string): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgConditionCustomFieldsPlugin: true;
}
}

namespace GraphileBuild {
interface ScopeInputObjectFieldsField {
isPgConnectionConditionInputField?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import type { GraphQLEnumType } from "grafast/graphql";

import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgConnectionArgOrderByDefaultValuePlugin: true;
}
}
}

export const PgConnectionArgOrderByDefaultValuePlugin: GraphileConfig.Plugin = {
name: "PgConnectionArgOrderByDefaultValuePlugin",
description: "Sets the default 'orderBy' for a table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { inspect } from "util";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgConnectionArgOrderByPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
orderByType(this: Inflection, typeName: string): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgConnectionTotalCountPlugin: true;
}
}

namespace GraphileBuild {
interface ScopeObjectFieldsField {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const $$rootMutation = Symbol("PgCustomTypeFieldPluginRootMutationSources");
const $$computed = Symbol("PgCustomTypeFieldPluginComputedSources");

declare global {
namespace GraphileConfig {
interface Plugins {
PgCustomTypeFieldPlugin: true;
}
}

namespace GraphileBuild {
interface Build {
pgGetArgDetailsFromParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgEnumTablesPlugin: true;
}

interface GatherHelpers {
pgEnumTables: {
isEnumConstraint(pgConstraint: PgConstraint): boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgFakeConstraintsPlugin: true;
}

interface GatherHelpers {
pgFakeConstraints: Record<string, never>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgFirstLastBeforeAfterArgsPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
conditionType(this: Inflection, typeName: string): string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { addBehaviorToTags } from "../utils.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgIndexBehaviorsPlugin: true;
}
}
}

export const PgIndexBehaviorsPlugin: GraphileConfig.Plugin = {
name: "PgIndexBehaviorsPlugin",
version: "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgInterfaceModeUnionAllRowsPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ declare global {
}

namespace GraphileConfig {
interface Plugins {
PgIntrospectionPlugin: true;
}

interface GatherHelpers {
pgIntrospection: {
getIntrospection(): PromiseOrDirect<IntrospectionResults>;
Expand Down
4 changes: 4 additions & 0 deletions graphile-build/graphile-build-pg/src/plugins/PgJWTPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ declare global {

declare global {
namespace GraphileConfig {
interface Plugins {
PgJWTPlugin: true;
}

interface GatherHelpers {
pgJWT: Record<string, never>;
}
Expand Down
8 changes: 8 additions & 0 deletions graphile-build/graphile-build-pg/src/plugins/PgLtreePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ interface State {
ltreeArrayCodec: PgCodec;
}

declare global {
namespace GraphileConfig {
interface Plugins {
PgLtreePlugin: true;
}
}
}

export const PgLtreePlugin: GraphileConfig.Plugin = {
name: "PgLtreePlugin",
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { tagToString } from "../utils.js";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgMutationCreatePlugin: true;
}
}

namespace GraphileBuild {
interface ScopeObject {
isPgCreatePayloadType?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import { version } from "../version.js";
import { applyOrderToPlan } from "./PgConnectionArgOrderByPlugin.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgMutationPayloadEdgePlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
tableEdgeField(this: Inflection, codec: PgCodecWithAttributes): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import { tagToString } from "../utils.js";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgMutationUpdateDeletePlugin: true;
}
}

namespace GraphileBuild {
interface ScopeObject {
isPgUpdatePayloadType?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgNodeIdAttributesPlugin: true;
}
}

namespace GraphileBuild {
interface Inflection {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { EXPORTABLE } from "graphile-build";
import { version } from "../version.js";

declare global {
namespace GraphileConfig {
interface Plugins {
PgOrderAllAttributesPlugin: true;
}
}
namespace GraphileBuild {
interface Inflection {
orderByAttributeEnum(
Expand Down
Loading

0 comments on commit 54c9027

Please sign in to comment.