Skip to content

Commit

Permalink
chore: apply suggestion from most review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne-Buschong committed Jun 10, 2024
1 parent 54e45be commit d5edc85
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 39 deletions.
43 changes: 42 additions & 1 deletion src/execution/execution-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OperationDefinitionNode } from 'graphql';
import { AuthContext } from '../authorization/auth-basics';
import { v4 as uuidv4 } from 'uuid';
import { AuthContext } from '../authorization/auth-basics';

export type MutationMode = 'normal' | 'disallowed' | 'rollback';

Expand Down Expand Up @@ -105,6 +105,47 @@ export interface ExecutionOptions {
* will be used.
*/
readonly idGenerator?: IDGenerator;

/**
* The maximum number of items that can be handled in a list-based root entity query/mutation.
*
* When then caller specifies a limit higher than this number an error is thrown prompting to reduce the limit.
*
* No checks are applied when this option is not set.
*
* It is applied to the following queries:
* - flexSearchAll<RootEntityPluralName>
* - all<RootEntityPluralName>
*
* It is applied to the following mutations:
* - updateAll<RootEntityPluralName>
* - deleteAll<RootEntityPluralName>
*
*/
readonly maxLimitForRootEntityQueries?: number;

/**
* The implicit maximum number of items that can be handled in a list-based root entity query/mutation.
*
* In contrast to `maxLimitForRootEntityQueries` this ensures that no more than the specified number of
* elements will be modified/queried in the queries/mutations it applies to, even when the caller does not
* specify a "first" parameter.
*
* When the limit is exceeded an error is thrown indicating to manually set a higher limit or explicitly
* truncate the available elements.
*
* No checks are applied when this option is not set.
*
* It is applied to the following queries:
* - flexSearchAll<RootEntityPluralName>
* - all<RootEntityPluralName>
*
* It is applied to the following mutations:
* - updateAll<RootEntityPluralName>
* - deleteAll<RootEntityPluralName>
*
*/
readonly implicitLimitForRootEntityQueries?: number;
}

export interface TimeToLiveExecutionOptions {
Expand Down
1 change: 1 addition & 0 deletions src/query-tree/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const NOT_FOUND_ERROR = 'NOT_FOUND';
export const FLEX_SEARCH_TOO_MANY_OBJECTS = 'FLEX_SEARCH_TOO_MANY_OBJECTS';
export const BILLING_KEY_FIELD_NOT_FILLED_ERROR = 'BILLING_KEY_FIELD_NOT_FILLED';
export const NOT_SUPPORTED_ERROR = 'NOT_SUPPORTED';
export const ARGUMENT_OUT_OF_RANGE_ERROR = 'ARGUMENT_OUT_OF_RANGE';

export const RUNTIME_ERROR_TOKEN = '__cruddl_runtime_error';
export const RUNTIME_ERROR_CODE_PROPERTY = '__cruddl_runtime_error_code';
Expand Down
29 changes: 22 additions & 7 deletions src/query-tree/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RelationSide, RootEntityType } from '../model';
import { TOO_MANY_OBJECTS_ERROR } from './../schema-generation/flex-search-generator';
import { QueryNode } from './base';

export interface QueryResultValidatorFunctionProvider {
Expand Down Expand Up @@ -113,7 +114,10 @@ export class ErrorIfNotTruthyResultValidator extends QueryNode implements QueryR
* a manual query limit can be applied.
*/
export class NoImplicitlyTruncatedListValidator extends QueryNode implements QueryResultValidator {
constructor(private readonly maximumExpectedNumberOfItems: number) {
constructor(
private readonly maximumExpectedNumberOfItems: number,
private readonly operation: string,
) {
super();
}

Expand All @@ -137,13 +141,23 @@ export class NoImplicitlyTruncatedListValidator extends QueryNode implements Que
}
}

const limit = validationData.maximumExpectedNumberOfItems;
if (result.length > validationData.maximumExpectedNumberOfItems) {
throw new RuntimeValidationError(
`Collection is truncated by default to ${validationData.maximumExpectedNumberOfItems} elements but contains more elements than this limit. Specify a limit manually to retrieve all elements of the collection.`,
{
code: validationData.errorCode,
},
);
if (validationData.operation === 'query') {
throw new RuntimeValidationError(
`Query would return more than ${limit} objects. Specify "first" to increase the limit or truncate the result.`,
{
code: TOO_MANY_OBJECTS_ERROR,
},
);
} else {
throw new RuntimeValidationError(
`Mutation would return more than ${limit} objects. Specify "first" to increase the limit or truncate the result`,
{
code: TOO_MANY_OBJECTS_ERROR,
},
);
}
}
};
}
Expand All @@ -159,6 +173,7 @@ export class NoImplicitlyTruncatedListValidator extends QueryNode implements Que
getValidatorData() {
return {
maximumExpectedNumberOfItems: this.maximumExpectedNumberOfItems,
operation: this.operation,
};
}

Expand Down
9 changes: 6 additions & 3 deletions src/schema-generation/flex-search-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ConditionalQueryNode,
ConstBoolQueryNode,
CountQueryNode,
FieldPathQueryNode,
FLEX_SEARCH_TOO_MANY_OBJECTS,
FieldPathQueryNode,
LiteralQueryNode,
PreExecQueryParms,
QueryNode,
Expand All @@ -35,7 +35,10 @@ import { decapitalize } from '../utils/utils';
import { FlexSearchFilterTypeGenerator } from './flex-search-filter-input-types';
import { FlexSearchFilterObjectType } from './flex-search-filter-input-types/filter-types';
import { FlexSearchPostFilterAugmentation } from './flex-search-post-filter-augmentation';
import { OrderByAndPaginationAugmentation } from './order-by-and-pagination-augmentation';
import {
LimitTypeCheckType,
OrderByAndPaginationAugmentation,
} from './order-by-and-pagination-augmentation';
import { OutputTypeGenerator } from './output-type-generator';
import {
QueryNodeField,
Expand Down Expand Up @@ -79,7 +82,7 @@ export class FlexSearchGenerator {
);
return this.augmentWithCondition(
this.orderByAugmentation.augment(withPostFilter, rootEntityType, {
firstLimitCheckType: 'Resolver',
firstLimitCheckType: LimitTypeCheckType.RESOLVER,
}),
rootEntityType,
);
Expand Down
1 change: 0 additions & 1 deletion src/schema-generation/list-augmentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Type } from '../model';
import { FilterAugmentation } from './filter-augmentation';
import {
LimitTypeCheckType,
OrderByAndPaginationAugmentation,
OrderByAndPaginationAugmentationOptions,
} from './order-by-and-pagination-augmentation';
Expand Down
17 changes: 13 additions & 4 deletions src/schema-generation/mutation-type-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
getUpdateEntitiesFieldName,
getUpdateEntityFieldName,
} from '../schema/names';
import { compact, decapitalize, PlainObject } from '../utils/utils';
import { PlainObject, compact, decapitalize } from '../utils/utils';
import { BillingTypeGenerator } from './billing-type-generator';
import { CreateInputTypeGenerator, CreateRootEntityInputType } from './create-input-types';
import { generateDeleteAllQueryNode } from './delete-all-generator';
Expand All @@ -48,11 +48,11 @@ import { ListAugmentation } from './list-augmentation';
import { OutputTypeGenerator } from './output-type-generator';
import {
FieldContext,
makeNonNullableList,
QueryNodeField,
QueryNodeListType,
QueryNodeNonNullType,
QueryNodeObjectType,
makeNonNullableList,
} from './query-node-object-type';
import { UniqueFieldArgumentsGenerator } from './unique-field-arguments-generator';
import {
Expand All @@ -68,6 +68,7 @@ import { getEntitiesByUniqueFieldQuery } from './utils/entities-by-unique-field'
import { getFilterNode } from './utils/filtering';
import { mapToIDNodesUnoptimized } from './utils/map';
import { getPreEntityRemovalStatements } from './utils/relations';
import { LimitTypeCheckType } from './order-by-and-pagination-augmentation';

export class MutationTypeGenerator {
constructor(
Expand Down Expand Up @@ -422,7 +423,10 @@ export class MutationTypeGenerator {
};

const fieldWithListArgs = this.listAugmentation.augment(fieldBase, rootEntityType, {
orderByAugmentationOptions: { firstLimitCheckType: 'ResultValidator' },
orderByAugmentationOptions: {
firstLimitCheckType: LimitTypeCheckType.RESULT_VALIDATOR,
operation: 'mutation',
},
});

const inputType =
Expand Down Expand Up @@ -631,7 +635,12 @@ export class MutationTypeGenerator {
resolve: () => new EntitiesQueryNode(rootEntityType),
};

const fieldWithListArgs = this.listAugmentation.augment(fieldBase, rootEntityType);
const fieldWithListArgs = this.listAugmentation.augment(fieldBase, rootEntityType, {
orderByAugmentationOptions: {
firstLimitCheckType: LimitTypeCheckType.RESULT_VALIDATOR,
operation: 'mutation',
},
});

return {
...fieldWithListArgs,
Expand Down
54 changes: 39 additions & 15 deletions src/schema-generation/order-by-and-pagination-augmentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql';

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.9, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 16.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.11, 18.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.8, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.

Check failure on line 1 in src/schema-generation/order-by-and-pagination-augmentation.ts

View workflow job for this annotation

GitHub Actions / test (arangodb:3.10, 14.x)

Property 'implicitLimitForRootEntityQueries' does not exist on type 'object'.
import { Type } from '../model';
import {
ARGUMENT_OUT_OF_RANGE_ERROR,
BinaryOperationQueryNode,
BinaryOperator,
BinaryOperatorWithAnalyzer,
Expand Down Expand Up @@ -43,13 +44,16 @@ import { RootFieldHelper } from './root-field-helper';
import { and, binaryOp, binaryOpWithAnaylzer } from './utils/input-types';
import { getOrderByValues } from './utils/pagination';

const MANUAL_MAX_COUNT_UPPER_BOUND = 50000;
const DEFAULT_MAX_COUNT_UPPER_BOUND = 10000;

export type LimitTypeCheckType = 'ResultValidator' | 'Resolver';
export enum LimitTypeCheckType {
RESULT_VALIDATOR,
RESOLVER,
}

export interface OrderByAndPaginationAugmentationOptions {
firstLimitCheckType?: LimitTypeCheckType;
operation?: 'query' | 'mutation';
maxLimitForRootEntityQueries?: number;
implicitLimitForRootEntityQueries?: number;
}

/**
Expand Down Expand Up @@ -107,12 +111,19 @@ export class OrderByAndPaginationAugmentation {
},
},
transformResult: (data: any, args: object) => {
if (options?.firstLimitCheckType !== 'Resolver' || 'first' in args) {
if (
options?.firstLimitCheckType !== LimitTypeCheckType.RESOLVER ||
'first' in args
) {
return data;
}
if (data.length > DEFAULT_MAX_COUNT_UPPER_BOUND) {
if (
'implicitLimitForRootEntityQueries' in args &&
typeof args.implicitLimitForRootEntityQueries === 'number' &&
data.length > args.implicitLimitForRootEntityQueries
) {
throw new Error(
`Collection is truncated by default to ${DEFAULT_MAX_COUNT_UPPER_BOUND} elements but contains more elements than this limit. Specify a limit manually to retrieve all elements of the collection.`,
`Collection is truncated by default to ${args.implicitLimitForRootEntityQueries} elements but contains more elements than this limit. Specify a limit manually to retrieve all elements of the collection.`,
);
}
return data;
Expand All @@ -126,17 +137,22 @@ export class OrderByAndPaginationAugmentation {

if (
options?.firstLimitCheckType &&
options?.maxLimitForRootEntityQueries &&
maxCount !== undefined &&
maxCount > MANUAL_MAX_COUNT_UPPER_BOUND
maxCount > options.maxLimitForRootEntityQueries
) {
return new RuntimeErrorQueryNode(
`The requested number of elements via the \"first\" parameter (${maxCount}) exceeds the maximum limit of ${MANUAL_MAX_COUNT_UPPER_BOUND}. Reduce the number of items you fetch and try again.`,
{ code: NOT_SUPPORTED_ERROR },
`The requested number of elements via the \"first\" parameter (${maxCount}) exceeds the maximum limit of ${options.maxLimitForRootEntityQueries}.`,
{ code: ARGUMENT_OUT_OF_RANGE_ERROR },
);
}

if (options?.firstLimitCheckType && maxCount === undefined) {
maxCount = DEFAULT_MAX_COUNT_UPPER_BOUND + 1;
if (
options?.firstLimitCheckType &&
options.implicitLimitForRootEntityQueries &&
maxCount === undefined
) {
maxCount = options.implicitLimitForRootEntityQueries + 1;
}

const skip = args[SKIP_ARG];
Expand Down Expand Up @@ -298,12 +314,14 @@ export class OrderByAndPaginationAugmentation {
});

if (
options?.firstLimitCheckType === 'ResultValidator' &&
options?.firstLimitCheckType === LimitTypeCheckType.RESULT_VALIDATOR &&
options.operation &&
args[FIRST_ARG] === undefined
) {
return this.wrapWithImplicitListTruncationResultValidator(
optimizedQueryNode,
maxCount,
options.operation,
);
}

Expand All @@ -323,13 +341,15 @@ export class OrderByAndPaginationAugmentation {
});

if (
options?.firstLimitCheckType === 'ResultValidator' &&
options?.firstLimitCheckType === LimitTypeCheckType.RESULT_VALIDATOR &&
options?.operation &&
args[FIRST_ARG] === undefined &&
maxCount
) {
return this.wrapWithImplicitListTruncationResultValidator(
transformListNode,
maxCount,
options.operation,
);
}

Expand All @@ -341,14 +361,18 @@ export class OrderByAndPaginationAugmentation {
private wrapWithImplicitListTruncationResultValidator(
queryNode: QueryNode,
maxCount: number,
operation: string,
): QueryNode {
const v = new VariableQueryNode();
return new WithPreExecutionQueryNode({
preExecQueries: [
new PreExecQueryParms({
query: queryNode,
resultVariable: v,
resultValidator: new NoImplicitlyTruncatedListValidator(maxCount - 1),
resultValidator: new NoImplicitlyTruncatedListValidator(
maxCount - 1,
operation,
),
}),
],
resultNode: v,
Expand Down
4 changes: 3 additions & 1 deletion src/schema-generation/query-node-object-type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'graphql';
import { GraphQLOutputType } from 'graphql/index';
import { ThunkReadonlyArray } from 'graphql/type/definition';
import { QueryNode, RuntimeErrorValue } from '../../query-tree';
import { QueryNode } from '../../query-tree';
import { FieldContext } from './context';

export interface QueryNodeResolveInfo extends FieldContext {}
Expand Down Expand Up @@ -38,6 +38,8 @@ export interface QueryNodeField {
* Will be called in the actual graphql field resolver for this node.
* Can be used to transform and validate a fields data after query-execution.
*
* Needs be synchronous, it is not possible to return a promise here.
*
* When the validation should roll back already made changes during a mutation it needs to be done
* via a PreExecQueryParms statement to have transactional guarantees.
*/
Expand Down
12 changes: 6 additions & 6 deletions src/schema-generation/query-node-object-type/field-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLFieldResolver } from 'graphql';
import { extractRuntimeError, isRuntimeErrorValue, RuntimeErrorValue } from '../../query-tree';
import { extractRuntimeError, isRuntimeErrorValue } from '../../query-tree';

/**
* A GraphQL field resolver for the query node object type framework
Expand All @@ -14,14 +14,14 @@ export function getFieldResolver(
return (source, args, context, info) => {
const fieldNode = info.fieldNodes[0];
const alias = fieldNode.alias ? fieldNode.alias.value : fieldNode.name.value;
const value = source[alias];
let value = source[alias];

if (isRuntimeErrorValue(value)) {
throw extractRuntimeError(value);
if (transformResult) {
value = transformResult(value, args);
}

if (transformResult) {
return transformResult(value, args);
if (isRuntimeErrorValue(value)) {
throw extractRuntimeError(value);
}

return value;
Expand Down
Loading

0 comments on commit d5edc85

Please sign in to comment.