Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable IAM auth for custom types #2961

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

palpatim
Copy link
Member

@palpatim palpatim commented Oct 16, 2024

Description of changes

Enables IAM authorization for custom types.

  • Unrelated change: Add a test case to ensure stacks properly emit warnings for Gen1-style schemas with implicit fields-style references

Issue #, if available

#2929

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@palpatim palpatim requested review from a team as code owners October 16, 2024 22:17
@palpatim palpatim force-pushed the palpatim.fix.add-iam-auth-to-custom-types branch from 858ea80 to 3563071 Compare October 16, 2024 22:19
@@ -161,6 +161,22 @@ describe('Deprecate Gen 1 patterns', () => {
);
});

test('does not allow implicit fields on @hasMany', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an opportunistic test addition that I found while I was investigating how a customer-provided GraphQL schema is being mutated in other contexts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this file from "defnition.test.ts", added the entire extendObjectWithDirectives block. Didn't touch the gets Non-Model Types block

Comment on lines +1 to +2
/* eslint-disable prefer-arrow/prefer-arrow-functions */
/* eslint-disable func-style */
Copy link
Member Author

@palpatim palpatim Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes this file easier to read in vscode since it suppresses the red squiggly eslint errors that would otherwise decorate the entire file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile with Neovim's LSP capabilities I apparently live in blissful ignorance.

p5quared
p5quared previously approved these changes Oct 16, 2024
Comment on lines +55 to +60
export const hasDirectiveWithName = (
node: FieldDefinitionNode | InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode,
name: string,
): boolean => {
return node.directives?.some((d) => d.name.value === name) ?? false;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible duplicate/extension of code here:

export const directiveExists = (definition: ObjectTypeDefinitionNode, name: string) => {
  return definition?.directives?.find((directive) => directive?.name?.value === name);
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks for finding that. I'll fix in a followup

const newDirectives = [];

for (const directive of directives) {
if (!object.directives.some((d) => d.name.value === directive.name.value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally could use hasDirectiveWithName but it also matches the rest of the functions in this file as is.

Comment on lines +1 to +2
/* eslint-disable prefer-arrow/prefer-arrow-functions */
/* eslint-disable func-style */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile with Neovim's LSP capabilities I apparently live in blissful ignorance.

Comment on lines +234 to +243
export const addDirectivesToObject = (
ctx: TransformerTransformSchemaStepContextProvider,
typeName: string,
directives: Array<DirectiveNode>,
): void => {
const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode;
if (type) {
ctx.output.putType(extendObjectWithDirectives(type, directives));
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This would break convention in this file...

Suggested change
export const addDirectivesToObject = (
ctx: TransformerTransformSchemaStepContextProvider,
typeName: string,
directives: Array<DirectiveNode>,
): void => {
const type = ctx.output.getType(typeName) as ObjectTypeDefinitionNode;
if (type) {
ctx.output.putType(extendObjectWithDirectives(type, directives));
}
};
export const addDirectivesToObject = (
ctx: TransformerTransformSchemaStepContextProvider,
typeName: string,
directives: Array<DirectiveNode>,
): void => {
const obj = ctx.output.getObject(typeName);
if (obj) {
ctx.output.updateObject(extendObjectWithDirectives(obj, directives));
}
};

@palpatim palpatim merged commit 8fc24f3 into main Oct 17, 2024
7 checks passed
@palpatim palpatim deleted the palpatim.fix.add-iam-auth-to-custom-types branch October 17, 2024 18:48
palpatim added a commit that referenced this pull request Oct 17, 2024
palpatim added a commit that referenced this pull request Oct 17, 2024
@palpatim
Copy link
Member Author

Reverted this b/c the manual test failed during deployment. Turns out that it was a different issue unrelated to this change, but we'll re-implement the change alongside an E2E, in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants