Skip to content

Commit

Permalink
fix: @function vNext payload, remove unused code, and update common m…
Browse files Browse the repository at this point in the history
…apping tempalte function (#8462)
  • Loading branch information
SwaySway committed Oct 15, 2021
1 parent 424bbda commit 24d0de9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 46 deletions.
26 changes: 1 addition & 25 deletions packages/amplify-graphql-auth-transformer/src/utils/schema.ts
@@ -1,10 +1,5 @@
import { ModelDirectiveConfiguration, SubscriptionLevel } from '@aws-amplify/graphql-model-transformer';
import {
DirectiveWrapper,
InvalidDirectiveError,
InvalidTransformerError,
TransformerContractError,
} from '@aws-amplify/graphql-transformer-core';
import { DirectiveWrapper, InvalidDirectiveError, TransformerContractError } from '@aws-amplify/graphql-transformer-core';
import {
QueryFieldType,
MutationFieldType,
Expand All @@ -23,7 +18,6 @@ import {
makeNamedType,
ModelResourceIDs,
plurality,
ResourceConstants,
toCamelCase,
toUpper,
} from 'graphql-transformer-common';
Expand All @@ -38,24 +32,6 @@ export const fieldIsList = (fields: ReadonlyArray<FieldDefinitionNode>, fieldNam
return fields.some(field => field.name.value === fieldName && isListType(field.type));
};

/**
* for the relational directives we either get the model name or a model connection name
*/
export const getModelObject = (
ctx: TransformerContextProvider,
typeName: string,
modelDirectiveConfig: Map<string, ModelDirectiveConfiguration>,
) => {
let modelObjectName: string = ModelResourceIDs.IsModelConnectionType(typeName)
? ModelResourceIDs.GetModelFromConnectionType(typeName)
: typeName;
if (modelDirectiveConfig.has(modelObjectName)) {
return ctx.output.getObject(modelObjectName);
} else {
throw new InvalidTransformerError(`Could not find @model named: ${typeName}`);
}
};

export const getModelConfig = (directive: DirectiveNode, typeName: string, isDataStoreEnabled = false): ModelDirectiveConfiguration => {
const directiveWrapped: DirectiveWrapper = new DirectiveWrapper(directive);
const options = directiveWrapped.getArguments<ModelDirectiveConfiguration>({
Expand Down
Expand Up @@ -7,8 +7,8 @@ Object {
\\"version\\": \\"2018-05-29\\",
\\"operation\\": \\"Invoke\\",
\\"payload\\": {
\\"typeName\\": $ctx.stash.get(\\"typeName\\"),
\\"fieldName\\": $ctx.stash.get(\\"fieldName\\"),
\\"typeName\\": $util.toJson($ctx.stash.get(\\"typeName\\")),
\\"fieldName\\": $util.toJson($ctx.stash.get(\\"fieldName\\")),
\\"arguments\\": $util.toJson($ctx.arguments),
\\"identity\\": $util.toJson($ctx.identity),
\\"source\\": $util.toJson($ctx.source),
Expand Down
Expand Up @@ -99,8 +99,8 @@ export class FunctionTransformer extends TransformerPluginBase {
version: str('2018-05-29'),
operation: str('Invoke'),
payload: obj({
typeName: ref('ctx.stash.get("typeName")'),
fieldName: ref('ctx.stash.get("fieldName")'),
typeName: ref('util.toJson($ctx.stash.get("typeName"))'),
fieldName: ref('util.toJson($ctx.stash.get("fieldName"))'),
arguments: ref('util.toJson($ctx.arguments)'),
identity: ref('util.toJson($ctx.identity)'),
source: ref('util.toJson($ctx.source)'),
Expand Down
Expand Up @@ -79,7 +79,7 @@ export class ModelResourceIDs {
return /^Model.*Connection$/.test(typeName);
}
static GetModelFromConnectionType(typeName: string): string {
return /(?<=Model)(.*)(?=Connection)/.exec(typeName)[0];
return /(?<=Model)(.*)(?=Connection)/.exec(typeName)?.[0];
}
static ModelDeleteInputObjectName(typeName: string): string {
return graphqlName('Delete' + toUpper(typeName) + 'Input');
Expand Down
Expand Up @@ -44,7 +44,6 @@ let LAMBDA_EXECUTION_POLICY_ARN = '';
const AUTH_ROLE_NAME = `${STACK_NAME}-authRole`;
const UNAUTH_ROLE_NAME = `${STACK_NAME}-unauthRole`;
let IAM_AUTH_CLIENT: AWSAppSyncClient<any> = undefined;
let USER_POOL_AUTH_CLIENT: AWSAppSyncClient<any> = undefined;
let USER_POOL_ID: string;
let IDENTITY_POOL_ID: string;
let GRAPHQL_ENDPOINT: string;
Expand Down Expand Up @@ -162,21 +161,7 @@ beforeAll(async () => {
configureAmplify(USER_POOL_ID, userPoolClientId, IDENTITY_POOL_ID);

await signupUser(USER_POOL_ID, USERNAME1, TMP_PASSWORD);
const authRes = await authenticateUser(USERNAME1, TMP_PASSWORD, REAL_PASSWORD);
const idToken = authRes.getIdToken().getJwtToken();

USER_POOL_AUTH_CLIENT = new AWSAppSyncClient({
url: endpoint,
region: REGION,
auth: {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: () => idToken,
},
offlineConfig: {
keyPrefix: 'userPools',
},
disableOffline: true,
});
await authenticateUser(USERNAME1, TMP_PASSWORD, REAL_PASSWORD);

await Auth.signIn(USERNAME1, REAL_PASSWORD);
const authCredentials = await Auth.currentCredentials();
Expand Down

0 comments on commit 24d0de9

Please sign in to comment.