|
| 1 | +import { FunctionTransformer } from '@aws-amplify/graphql-function-transformer'; |
1 | 2 | import { ModelTransformer } from '@aws-amplify/graphql-model-transformer'; |
2 | 3 | import { mockSqlDataSourceStrategy, testTransform } from '@aws-amplify/graphql-transformer-test-utils'; |
3 | 4 | import { PrimaryKeyTransformer } from '@aws-amplify/graphql-index-transformer'; |
@@ -40,6 +41,7 @@ const makeTransformers = (): TransformerPluginProvider[] => [ |
40 | 41 | new AuthTransformer(), |
41 | 42 | new PrimaryKeyTransformer(), |
42 | 43 | new SqlTransformer(), |
| 44 | + new FunctionTransformer(), |
43 | 45 | ]; |
44 | 46 |
|
45 | 47 | const makeSqlDirectiveDataSourceStrategies = (schema: string, strategy: ModelDataSourceStrategy): SqlDirectiveDataSourceStrategy[] => |
@@ -367,8 +369,7 @@ describe('Custom operations have @aws_iam directives when enableIamAuthorization |
367 | 369 | expect(out.schema).not.toMatch(/onUpdateFooCustom: String.*@aws_iam/); |
368 | 370 | }); |
369 | 371 |
|
370 | | - // TODO: Enable this test once we fix https://github.com/aws-amplify/amplify-category-api/issues/2929 |
371 | | - test.skip('Adds @aws_iam to non-model custom types when there is no model', () => { |
| 372 | + test('Adds @aws_iam to non-model custom types when there is no model', () => { |
372 | 373 | const strategy = makeStrategy(strategyType); |
373 | 374 | const schema = /* GraphQL */ ` |
374 | 375 | type Foo { |
@@ -403,8 +404,7 @@ describe('Custom operations have @aws_iam directives when enableIamAuthorization |
403 | 404 | expect(out.schema).toMatch(/type Foo.*@aws_iam/); |
404 | 405 | }); |
405 | 406 |
|
406 | | - // TODO: Enable this test once we fix https://github.com/aws-amplify/amplify-category-api/issues/2929 |
407 | | - test.skip('Adds @aws_iam to non-model custom types when there is a model', () => { |
| 407 | + test('Adds @aws_iam to non-model custom types when there is a model', () => { |
408 | 408 | const strategy = makeStrategy(strategyType); |
409 | 409 | const schema = /* GraphQL */ ` |
410 | 410 | type Todo @model { |
@@ -478,6 +478,42 @@ describe('Custom operations have @aws_iam directives when enableIamAuthorization |
478 | 478 | expect(out.schema).toMatch(/description: String.*@aws_iam/); |
479 | 479 | }); |
480 | 480 |
|
| 481 | + test('Adds @aws_iam to async function EventInvocationResponse type', () => { |
| 482 | + const strategy = makeStrategy(strategyType); |
| 483 | + const schema = /* GraphQL */ ` |
| 484 | + type Foo { |
| 485 | + description: String |
| 486 | + } |
| 487 | + type EventInvocationResponse @aws_api_key { |
| 488 | + success: Boolean! |
| 489 | + } |
| 490 | + type Query { |
| 491 | + getFooCustom: Foo |
| 492 | + } |
| 493 | + type Mutation { |
| 494 | + updateFooCustom: Foo |
| 495 | + doSomethingAsync(body: String!): EventInvocationResponse |
| 496 | + @function(name: "FnDoSomethingAsync", invocationType: Event) |
| 497 | + @auth(rules: [{ allow: public, provider: apiKey }]) |
| 498 | + } |
| 499 | + type Subscription { |
| 500 | + onUpdateFooCustom: Foo @aws_subscribe(mutations: ["updateFooCustom"]) |
| 501 | + } |
| 502 | + `; |
| 503 | + |
| 504 | + const out = testTransform({ |
| 505 | + schema, |
| 506 | + dataSourceStrategies: constructDataSourceStrategies(schema, strategy), |
| 507 | + authConfig: makeAuthConfig(), |
| 508 | + synthParameters: makeSynthParameters(), |
| 509 | + transformers: makeTransformers(), |
| 510 | + sqlDirectiveDataSourceStrategies: makeSqlDirectiveDataSourceStrategies(schema, strategy), |
| 511 | + }); |
| 512 | + |
| 513 | + // Also expect the custom type referenced by the custom operation to be authorized |
| 514 | + expect(out.schema).toMatch(/type EventInvocationResponse.*@aws_iam/); |
| 515 | + }); |
| 516 | + |
481 | 517 | test('Does not add duplicate @aws_iam directive to custom type if already present', () => { |
482 | 518 | const strategy = makeStrategy(strategyType); |
483 | 519 | const schema = /* GraphQL */ ` |
|
0 commit comments