Skip to content

Commit

Permalink
fix: move storage check in @predictions v2 (#7816)
Browse files Browse the repository at this point in the history
@predictions requires that storage is configured. This commit
moves the check out of the before() phase, as that is invoked
even if @predictions is not used in the schema, leading to
unnecessary errors.

Co-authored-by: Colin Ihrig <[email protected]>
  • Loading branch information
cjihrig and cjihrig-aws authored Jul 27, 2021
1 parent b39141e commit d060a41
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';
import { DirectiveWrapper, InvalidDirectiveError, MappingTemplate, TransformerPluginBase } from '@aws-amplify/graphql-transformer-core';
import {
TransformerBeforeStepContextProvider,
TransformerContextProvider,
TransformerSchemaVisitStepContextProvider,
TransformerTransformSchemaStepContextProvider,
Expand Down Expand Up @@ -71,18 +70,16 @@ export class PredictionsTransformer extends TransformerPluginBase {
this.bucketName = predictionsConfig?.bucketName ?? '';
}

before = (context: TransformerBeforeStepContextProvider): void => {
if (!this.bucketName) {
throw new InvalidDirectiveError('Please configure storage in your project in order to use the @predictions directive');
}
};

field = (
parent: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode,
definition: FieldDefinitionNode,
directive: DirectiveNode,
context: TransformerSchemaVisitStepContextProvider,
): void => {
if (!this.bucketName) {
throw new InvalidDirectiveError('Please configure storage in your project in order to use the @predictions directive');
}

if (parent.name.value !== context.output.getQueryTypeName()) {
throw new InvalidDirectiveError('@predictions directive only works under Query operations.');
}
Expand Down

0 comments on commit d060a41

Please sign in to comment.