Skip to content

Commit

Permalink
WIP on inputs' improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
yvann committed Jan 24, 2025
1 parent 56d42e5 commit b625e13
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 291 deletions.
2 changes: 0 additions & 2 deletions packages/graphql-platform/src/node/operation/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ export type Mutation<TRequestContext extends object = any> =
| Creation<TRequestContext>
| Update<TRequestContext>
| Deletion<TRequestContext>
// | ReplaceMutation<TRequestContext>
| UpsertMutation<TRequestContext>
| AbstractMutation<any, any, TRequestContext>;

export const mutationConstructors = [
...creationConstructors,
...updateConstructors,
...deletionConstructors,
// ReplaceMutation,
UpsertMutation,
] satisfies Constructor<Mutation, [Node]>[];
126 changes: 0 additions & 126 deletions packages/graphql-platform/src/node/operation/mutation/replace.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MGetter } from '@prismamedia/memoize';
import assert from 'node:assert';
import type { Node } from '../../../../node.js';
import { Leaf } from '../../../definition.js';
import { OrderingDirection } from '../../../statement.js';
import type { LeafOrderingInput } from '../../../type.js';
import { OrderingDirection } from '../../../statement/ordering/direction.js';
import type { LeafOrderingInput } from '../../../type/input/ordering/expression/leaf.js';

export type ScrollSubscriptionOrderingInputValue = utils.Nillable<
LeafOrderingInput['value']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
OrderingDirection,
type NodeSelectedValue,
} from '../../../statement.js';
import { LeafFilterInput, type NodeFilterInputValue } from '../../../type.js';
import type { NodeFilterInputValue } from '../../../type/input/filter.js';
import { LeafFilterInput } from '../../../type/input/filter/field/leaf.js';

const averageFormattedKey = 'average_formatted';

Expand Down
34 changes: 15 additions & 19 deletions packages/graphql-platform/src/node/type/input/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {
sortableLeafComparisonOperatorSet,
type BooleanFilter,
} from '../../statement/filter.js';
import {
BooleanOperationFilterInput,
EdgeFilterInput,
LeafFilterInput,
ReverseEdgeFilterInput,
type AbstractFieldFilterInput,
} from './filter/field.js';
import { FieldFilterInput } from './filter/field.js';
import { EdgeFilterInput } from './filter/field/edge.js';
import { LeafFilterInput } from './filter/field/leaf.js';
import { ReverseEdgeFilterInput } from './filter/field/reverse-edge.js';

export * from './filter/field.js';
export * from './filter/field/edge.js';
export * from './filter/field/leaf.js';
export * from './filter/field/reverse-edge.js';

export type NodeFilterInputValue = utils.Nillable<utils.PlainObject>;

Expand All @@ -40,7 +40,7 @@ export type NodeFilterInputTypeOverride = {
description?: string;
};

export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilterInput> {
export class NodeFilterInputType extends utils.ObjectInputType<FieldFilterInput> {
public static createLeafComparisonFields(leaf: Leaf): LeafFilterInput[] {
const fields: LeafFilterInput[] = [];

Expand Down Expand Up @@ -332,10 +332,6 @@ export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilt
...(['eq', 'not', 'gt', 'gte', 'lt', 'lte'] as const).map(
(operator) =>
new ReverseEdgeFilterInput<number>(reverseEdge, `count_${operator}`, {
name:
operator === 'eq'
? reverseEdge.countFieldName
: `${reverseEdge.countFieldName}_${operator}`,
type: new utils.NonNullableInputType(
scalars.typesByName.UnsignedInt,
),
Expand Down Expand Up @@ -368,9 +364,9 @@ export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilt
});
}

public createBooleanOperationFields(): BooleanOperationFilterInput[] {
public createBooleanOperationFields(): FieldFilterInput[] {
return [
new BooleanOperationFilterInput<NodeFilterInputValue[]>({
new FieldFilterInput<NodeFilterInputValue[]>({
name: 'AND',
type: new utils.NonNullableInputType(new utils.ListableInputType(this)),
filter: (values, context, path) =>
Expand All @@ -386,7 +382,7 @@ export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilt
),
),
}),
new BooleanOperationFilterInput<NodeFilterInputValue[]>({
new FieldFilterInput<NodeFilterInputValue[]>({
name: 'OR',
type: new utils.NonNullableInputType(new utils.ListableInputType(this)),
filter: (values, context, path) =>
Expand All @@ -402,7 +398,7 @@ export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilt
),
),
}),
new BooleanOperationFilterInput<NodeFilterInputValue>({
new FieldFilterInput<NodeFilterInputValue>({
name: 'NOT',
type: this,
filter: (value, context, path) =>
Expand All @@ -412,20 +408,20 @@ export class NodeFilterInputType extends utils.ObjectInputType<AbstractFieldFilt
}

@MGetter
public override get fields(): ReadonlyArray<AbstractFieldFilterInput> {
public override get fields(): ReadonlyArray<FieldFilterInput> {
const constructor = this.constructor as typeof NodeFilterInputType;

return [
...this.node.componentSet
.values()
.flatMap<AbstractFieldFilterInput>((component) =>
.flatMap<FieldFilterInput>((component) =>
component instanceof Leaf
? constructor.createLeafFields(component)
: constructor.createEdgeFields(component),
),
...this.node.reverseEdgeSet
.values()
.flatMap<AbstractFieldFilterInput>((reverseEdge) =>
.flatMap<FieldFilterInput>((reverseEdge) =>
reverseEdge instanceof UniqueReverseEdge
? constructor.createUniqueReverseEdgeFields(reverseEdge)
: constructor.createMultipleReverseEdgeFields(reverseEdge),
Expand Down

This file was deleted.

30 changes: 25 additions & 5 deletions packages/graphql-platform/src/node/type/input/filter/field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
export * from './abstract-field.js';
export * from './field/boolean-operation.js';
export * from './field/edge.js';
export * from './field/leaf.js';
export * from './field/reverse-edge.js';
import * as utils from '@prismamedia/graphql-platform-utils';
import type { Except } from 'type-fest';
import type { OperationContext } from '../../../operation/context.js';
import type { BooleanFilter } from '../../../statement/filter/boolean.js';

export type FieldFilterInputConfig<TValue> = Except<
utils.InputConfig<TValue>,
'defaultValue' | 'parser'
> & {
filter(
value: Exclude<TValue, undefined>,
context: OperationContext | undefined,
path: utils.Path,
): BooleanFilter;
};

export class FieldFilterInput<TValue = any> extends utils.Input<TValue> {
public readonly filter: FieldFilterInputConfig<TValue>['filter'];

public constructor({ filter, ...config }: FieldFilterInputConfig<TValue>) {
super(config);

this.filter = filter;
}
}

This file was deleted.

24 changes: 8 additions & 16 deletions packages/graphql-platform/src/node/type/input/filter/field/edge.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import type { Except, SetOptional } from 'type-fest';
import type { Edge } from '../../../../definition/component/edge.js';
import {
AbstractFieldFilterInput,
type AbstractFieldFilterInputConfig,
} from '../abstract-field.js';
import type { Except } from 'type-fest';
import type { Edge } from '../../../../definition.js';
import { FieldFilterInput, type FieldFilterInputConfig } from '../field.js';

export type EdgeFilterInputConfig<TValue> = Except<
SetOptional<AbstractFieldFilterInputConfig<TValue>, 'name'>,
'public'
FieldFilterInputConfig<TValue>,
'name' | 'public'
>;

export class EdgeFilterInput<
TValue = any,
> extends AbstractFieldFilterInput<TValue> {
export class EdgeFilterInput<TValue = any> extends FieldFilterInput<TValue> {
public constructor(
public readonly edge: Edge,
public readonly id: string,
{
name = id === 'eq' ? edge.name : `${edge.name}_${id}`,
...config
}: EdgeFilterInputConfig<TValue>,
config: EdgeFilterInputConfig<TValue>,
) {
super({
deprecated: edge.deprecationReason,
...config,
name,
name: id === 'eq' ? edge.name : `${edge.name}_${id}`,
public: edge.isPublic(),
});
}
Expand Down
Loading

0 comments on commit b625e13

Please # to comment.