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

feat: generate api code #269

Merged
merged 6 commits into from
Sep 22, 2023
Merged

feat: generate api code #269

merged 6 commits into from
Sep 22, 2023

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Sep 22, 2023

Issue #, if available:

Description of changes:

  • Add wrapper to around types, documents, and model generation (generateAPICode).
  • Change createGraphqlDocumentGenerator and createGraphqlTypesGenerator to use backendIdentifier and credentialProvider.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2023

🦋 Changeset detected

Latest commit: 138da96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/model-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Base automatically changed from models to main September 22, 2023 17:13
@dpilch dpilch changed the base branch from main to generate-client-code-command September 22, 2023 17:14
@dpilch dpilch force-pushed the generate-api-code branch 4 times, most recently from 689bdf3 to faea5eb Compare September 22, 2023 20:20
@dpilch dpilch changed the base branch from generate-client-code-command to main September 22, 2023 20:20
@dpilch dpilch force-pushed the generate-api-code branch 2 times, most recently from fff9686 to 4963b85 Compare September 22, 2023 20:30
@dpilch dpilch marked this pull request as ready for review September 22, 2023 20:48
Copy link
Member

@sobolk sobolk left a comment

Choose a reason for hiding this comment

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

looks good.

packages/model-generator/API.md Show resolved Hide resolved
packages/model-generator/API.md Outdated Show resolved Hide resolved
packages/model-generator/API.md Outdated Show resolved Hide resolved
packages/model-generator/API.md Outdated Show resolved Hide resolved
Comment on lines 29 to 32
// @public (undocumented)
export type GeneratedOutput = {
[filename: string]: string;
};
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be unused. please hide.

Copy link
Member Author

Choose a reason for hiding this comment

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

The is the return type of generateApiCode.

Copy link
Member

Choose a reason for hiding this comment

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

hmm.
In that case shouldn't generateApiCode just return GenerationResult like the wrapped operations do?
Do we have use case where in-memory representation would be consumed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update to GenerationResult. The in-memory functionality was a requirement from Rene and is how Al's PR is built https://github.com/aws-amplify/samsara-cli/pull/265/files#diff-dcea9a2f178bf1deb339fd2cc2aa95b9cf136b2f32a660c1c3501f8bd62c399dR30-R57

Copy link
Member

Choose a reason for hiding this comment

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

Al's PR can use GenerationResult.writeToDirectory() API. Which was created for that purpose.

@alharris-at do you know why PMs want in-memory representation? Can this be descoped for now until we know what is the use case?

Regardless of whether it's a must or not the GenerationResult was a place to add Record<string, string> prop to provide that. But if we don't know use case we should hold.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine chopping this out for now.

// @public (undocumented)
export type GenerationResult = {
writeToDirectory: (directoryPath: string) => Promise<void>;
operations: Record<string, string>;
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a use case for this?
If not please hide.

@@ -12,7 +12,7 @@ export class AppsyncGraphqlGenerationResult implements GenerationResult {
* @param operations A record of FileName to FileContent
* in the format of Record<string,string>
*/
constructor(private operations: ClientOperations) {}
constructor(public operations: ClientOperations) {}
Copy link
Member

Choose a reason for hiding this comment

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

why ?

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 is so that generateApiCode can return the generation results without writing to the file system.

Comment on lines -31 to -32
maxDepth: 3,
typenameIntrospection: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Will dropping these defaults impact form gen, or is Spencer already passing these in?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is being used by the form generation yet. @sdstolworthy

packages/model-generator/src/generate_api_code.ts Outdated Show resolved Hide resolved
alharris-at
alharris-at previously approved these changes Sep 22, 2023
alharris-at
alharris-at previously approved these changes Sep 22, 2023
sobolk
sobolk previously approved these changes Sep 22, 2023
target: props.typeTarget,
multipleSwiftFiles: props.multipleSwiftFiles,
});
return { ...documents, ...types };
Copy link
Member Author

Choose a reason for hiding this comment

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

I need to fix this to be a new combined GenerationResult.

Comment on lines +23 to +29
// @public
export const generateApiCode: (props: GenerateApiCodeProps) => Promise<GenerationResult>;

// @public (undocumented)
export type GenerateApiCodeProps = GenerateOptions & BackendIdentifier & {
credentialProvider: AwsCredentialIdentityProvider;
};
Copy link
Member

Choose a reason for hiding this comment

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

One more suggestion.
Rest of APIs are explicit about Graphql
Should we use generateGraphqlApiCode (and similar in props/return) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Rene wanted customer facing APIs to use "API" over "Graphql". We'll be syncing with him on naming next week to finalize.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we'll be able to close on this by EOD Monday, but I wouldn't make it block this, since we want this in for the pentest ready date, which is also monday (easy to change)

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

Also. Then
If this is customer facing I suggest to consider moving other types to namespaces.

So that import * as generator from '@aws-amplify/model-generator' does not cause explosion in IDE when customer types generator. .

For example other types can be moved to @aws-amplify/model-generator/documents @aws-amplify/model-generator/types what not. We do that in other packages that are customer facing like here:
https://github.com/aws-amplify/samsara-cli/blob/4fd18b126ba075d054ddc4b34859e67e519355e5/packages/client-config/package.json#L8-L18

@dpilch dpilch dismissed stale reviews from sobolk and alharris-at via 138da96 September 22, 2023 22:24
@dpilch dpilch merged commit b48dae8 into main Sep 22, 2023
@dpilch dpilch deleted the generate-api-code branch September 22, 2023 22:41
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.

3 participants