Skip to content

Commit 65a8ce2

Browse files
AnilMaktalarenebrandeljosefaidt
authored
Graphql generate client code (#7176)
* updated generate-client-code section * updated graphql-client-code section * updated the description * removed workflow * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: Rene Brandel <4989523+renebrandel@users.noreply.github.com> * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: Rene Brandel <4989523+renebrandel@users.noreply.github.com> * added Supported GraphQL client code combinations * fixed the spell * fixed the format * fixed the syntax * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: josef <josef.aidt@gmail.com> * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: josef <josef.aidt@gmail.com> * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: josef <josef.aidt@gmail.com> * Update src/pages/gen2/reference/cli-commands/index.mdx Co-authored-by: josef <josef.aidt@gmail.com> * updated the stack name --------- Co-authored-by: Rene Brandel <4989523+renebrandel@users.noreply.github.com> Co-authored-by: josef <josef.aidt@gmail.com>
1 parent 0315580 commit 65a8ce2

File tree

1 file changed

+74
-2
lines changed
  • src/pages/gen2/reference/cli-commands

1 file changed

+74
-2
lines changed

src/pages/gen2/reference/cli-commands/index.mdx

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,81 @@ npx amplify generate config --stack amplify-nextamplifygen2-josef-sandbox-ca85e1
215215

216216
## npx amplify generate graphql-client-code
217217

218-
Generate GraphQL statements for your frontend application to consume.
218+
Generate GraphQL statements and types for your frontend application to consume.
219+
220+
<SubCommandHeading parentCommand="amplify-generate-graphql-client-code">Options</SubCommandHeading>
221+
222+
The available parameters for `npx amplify generate graphql-client-code` are:
223+
224+
Required parameters:
225+
- Stack identifier
226+
- `--stack`(_string_) - A stack name that contains an Amplify backend.
227+
- Project identifier
228+
- `--app-id`(_string_) - The Amplify App ID of the project.
229+
- `--branch`(_string_) - A git branch of the Amplify project.
230+
231+
Optional parameters:
232+
- `--out`(_string_) - Specifies the path to the directory where the config is written. If not provided, defaults to the current process working directory.
233+
- `--format`(_string_) (choices: `modelgen`, `graphql-codegen`, `introspection`) - Specifies the format of the GraphQL client code to be generated.
234+
- `--model-target` (_string_) (choices: `java`, `swift`, `javascript`, `typescript`, `dart`) - Specifies the modelgen export target. Only applies when the --format parameter is set to modelgen.
235+
- `--statement-target`(_string_) (choices: `javascript`, `graphql`, `flow`, `typescript`, `angular`) - Specifies the graphql-codegen statement export target. Only applies when the --format parameter is set to graphql-codegen.
236+
- `--type-target`(_string_) (choices: `json`, `swift`, `typescript`, `flow`, `scala`, `flow-modern`, `angular`) - Specifies the optional graphql-codegen type export target. Only applies when the --format parameter is set to graphql-codegen.
237+
- `--all`(_boolean_)- Shows hidden options.
238+
- `--profile`(_string_) - Specifies an AWS profile name.
239+
- `--debug` (_boolean_) - Print debug logs to the console.
240+
- `--help`(_boolean_) - Displays help information about the command.
241+
<SubCommandHeading parentCommand="amplify-generate-graphql-client-code">Usage</SubCommandHeading>
242+
243+
244+
### Generate GraphQL client code using the Amplify App ID and branch.
245+
```bash title="Terminal" showLineNumbers={false}
246+
npx amplify generate graphql-client-code --app-id <your-amplify-app-id> --branch staging
247+
```
248+
### Generate GraphQL client code for a branch that is connected in the Amplify service
249+
Sometimes you want to test your latest local changes with the backend of another deployed branch. If you want to generate the GraphQL client code file(s) for the latest deployment of another branch, then you can run the following command:
250+
251+
```bash title="Terminal" showLineNumbers={false}
252+
npx amplify generate graphql-client-code --branch staging
253+
```
254+
### Generate codegen for CDK app using a joint "AmplifyBackendStack" construct
255+
Assume you have deployed your Amplify project with the CDK construct. You will need to remember your app's project name (designated as the second parameter in your CDK construct) and stack name (designated as part of your `npx cdk deploy` context)
256+
257+
```ts title="lib/stack.ts" showLineNumbers={false}
258+
import { Construct } from 'constructs';
259+
import { App, Backend } from 'aws-cdk-lib/aws-amplify';
260+
261+
export class MyAmplifyStack extends cdk.Stack {
262+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
263+
super(scope, id, props);
264+
265+
new Backend(this, "Backend", { /* ... */ });
266+
}
267+
}
268+
```
269+
### Deployment command for CDK project
270+
```bash title="Terminal" showLineNumbers={false}
271+
npx cdk deploy
272+
```
273+
Run Amplify codegen command to generate GraphQL codegen:
274+
```bash title="Terminal" showLineNumbers={false}
275+
npx amplify generate graphql-client-code --stack Backend --platform ts --out ./src
276+
```
277+
### Generate codegen in specific language and format
278+
279+
```bash title="Terminal" showLineNumbers={false}
280+
npx amplify generate graphql-client-code --format modelgen --type-target angular
281+
```
282+
### Supported GraphQL client code combinations:
283+
284+
| Format | Platform | Codegen command in Amplify CLI | Command in Amplify Gen2 | Default generated file/path |
285+
| -------| -------- | ------------------------------ | ----------------------- | --------------------------- |
286+
| Introspection schema | Amplify Javascript | N/A | `npx amplify generate graphql-client-code --format introspection` | `<path_to_app>/` |
287+
| GraphQL codegen | Amplify Javascript | `amplify codegen` | `npx amplify generate graphql-client-code --format graphql-codegen --statement-target javascript --out <path_to_app>/src/graphql/` | `<path_to_app>/src/graphql/` |
288+
| Modelgen | Amplify Javascript | `amplify codegen model` | `npx amplify generate graphql-client-code --format modelgen --model-target javascript --out <path_to_app>/src/models/` | `<path_to_app>/src/models/` |
289+
| Modelgen | Amplify Android | `amplify codegen model` | `npx amplify generate graphql-client-code --format modelgen --model-target java --out <path_to_app/src/main/java/>` | `<path_to_app>/src/main/java/com/amplifyframework/datastore/generated/model` |
290+
| Modelgen | Amplify Swift | `amplify codegen model` | `npx amplify generate graphql-client-code --format modelgen --model-target swift --out <path_to_swift_project>/AmplifyModels` | `<path_to_swift_project>/AmplifyModels` |
291+
| Modelgen | Amplify Flutter | `amplify codegen model` | `npx amplify generate graphql-client-code --format modelgen --model-target dart --out <path_to_flutter_project>/AmplifyModels` | `<path_to_flutter_project>/AmplifyModels` |
219292

220-
{/* @TODO */}
221293

222294
## npx amplify generate forms
223295

0 commit comments

Comments
 (0)