AWS Amplify GraphQL API changing the nested level depth for codegenerator - aws-amplify

In AWS Amplify CLI when you add a GrpahQL API with
amplify add api
you are asked for the max level depth of the generated code. The default nested level is 3.
In my case it turns out that the max depth is not enough and I need to increase it.
Is there a way to do that?
I'we tried to run
amplify update api
However I wasn't asked again about the maximum level depth of the generated code during the process of the update.

Finally I've found the solution in this github asnwer.
Turns out that the file .graphqlconfig.yml is responsible for the AWS Amplify GraphQL API.
The property projects.YOUR-API-NAME.extensions.amplify.maxDepth is responsible for changing the nested level depth for the codegenerator. Now my .graphqlconfig.yml file looks in the following way and it works:
projects:
YOUR-API-NAME:
schemaPath: amplify/backend/api/zlmvp/build/schema.graphql
includes:
- src/graphql/**/*.ts
excludes:
- ./amplify/**
extensions:
amplify:
codeGenTarget: typescript
generatedFileName: src/API.ts
docsFilePath: src/graphql
maxDepth: 5
extensions:
amplify:
version: 3

Related

Firebase Deploy Error: 'Changing secrets is not supported' when using separate projects with Stripe 'Run Payments with Stripe' extension

I'm trying to setup multiple environments for my Vue / Firebase Project.
I have two Firebase Projects
1.) Dev
2.) Prod
The project utilizes Stripe Extension which pulls the API Key from an auto-generated file called:
firestore-stripe-payments.env
which contains:
STRIPE_API_KEY=projects/${param:PROJECT_NUMBER}/secrets/firestore-stripe-payments-STRIPE_API_KEY-xxxx/versions/latest
Where xxxx is a random 4 character string.
That line pulls the value of the key from Google Secret Manager.
Let's say Dev is 'dddd'
and Prod is: 'pppp'
The issue is that I can only define either:
firestore-stripe-payments-STRIPE_API_KEY-dddd
or
firestore-stripe-payments-STRIPE_API_KEY-pppp
At first I tried to create a new value within Google Secret Manager simply called:
firestore-stripe-payments-STRIPE_API_KEY
The thought was this should be a simple fix, and it would pull the associated API_KEY for the project currently being used.
but this causes the error:
Error: firestore-stripe-payments: Found 'projects/foo/secrets/firestore-stripe-payments-STRIPE_API_KEY/versions/latest' for secret param STRIPE_API_KEY, but this instance was previously using a different secret projects/fooo/secrets/firestore-stripe-payments-STRIPE_API_KEY-dddd.
Changing secrets is not supported. If you want to change the value of this secret, use a new version of projects/foo/secrets/firestore-stripe-payments-STRIPE_API_KEY-dddd.You can create a new version at https://console.cloud.google.com/security/secret-manager?project=fooo
Also, if there is a better place to ask this question please let me know, couldn't find the 'right' room
For this scenario, could you include a separate env (env.dev) file using the following guidelines
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local
For generating separate keys for each environment, I believe from your example you are using a single Stripe Extension on a single project.
Firebase Extensions can support multiple instances of an Extension per project, this will create a separate "dev" secret for you to use.
Additionally, a separate Firebase project with another "Stripe Extension" installation would be recommended to separate any concerns in development.

how to run amplify codegen in where codegen is already configured?

we have a project repo where backend team have added new apis.
other developers have run and configured amplify and codegen.
now I want to add these new queries and their types.
when I run amplify codegen i get this error:
Please download the schema.graphql or schema.json and place in C:\leag\nevClon\newwebsite before adding codegen when not in an amplify project
and when i run amplify add codegen it says Codegen support only one GraphQL API per project.
could someone guide me whats the right way to do that.
I've seen this problem in the past. Things I've tried include ...
Make sure you are in the correct amplify environment.
Run amplify pull to ensure you are up to date.
Try re-initializing using amplify init
When all else fails, try re-cloning the repository.

How to configure fail-fast strategy for Zuul CI jobs for a specific project?

How can someone configure a specific project (repository) to use a fail-fast strategy for jobs running inside it?
fail-fast strategy on CI means that you want to cancel any running jobs as soon the first one that counts towards final result is failing (saving compute resources and providing a faster feedback).
Please note that I explicitly asked about a specific project as this option should not affect other project that may have different preferences.
The fail-fast option is already by design a per project (or per project-template) and pipeline setting [1].
e.g. from within an untrusted project:
- project:
check:
fail-fast: true
jobs:
- test foo
Or you can set it in a config project for a different project:
- project:
name: org/other-project
check:
fail-fast: true
[1] https://zuul-ci.org/docs/zuul/reference/project_def.html#attr-project.%3Cpipeline%3E.fail-fast

Is it possible to generate models manually?

I have a JS project that uses aws services as a backend (Cognito, AppSync, S3, etc).
I use AWS Amplify to access these services but do not use the amplify CLI; all aws services are configuredd manually.
Regarding AppSync, I have a little script that reads the schema (downloaded manually from the appsync console) and then generates Typescript operations and operation types files (using amplify-graphql-docs-generator and amplify-graphql-types-generator).
Is it possible to do the same for models, ie generate a models file in typescript based on a local schema file ? Or in other words how can I replicate amplify codegen models inside a project that was not setup with the amplify-cli ?
You can probably check the implementation of the amplify codegen and find its inner workings
https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-codegen
Or if you don't mind using the Amplify CLI, you can hook up an existing AppSync project running the following commands in sequence at the project root:
amplify init
amplify add codegen --apiId xxxx
amplify codegen

Restoring Previous instance of AWS Appsync schema

I hope I can explain this well.
So I created a react app with amplify and pushed my schema and went on to modify and create the various resolvers I require upon discovering that if I performed "amplify push" again because I changed or modified added a new field all the resolvers would also be reset I started updating my schema directly in the Appsync console so I won't have to redo the resolvers each time I wanted to change something. Now unfortunately I somehow performed amplify push which has removed all of my resolvers again. So my question is... is there a way to restore my shema to it's previous state and bring back all the missing resolvers?
Thanks.
First, did you version control your resolvers? I don't AppSync versions your resolvers or keeps backups, but you might want to contact the service team immediately to see if they can restore any resolvers that only existed in the AppSync API.
Second: did you change the default resolvers, or create new ones?
If you want to override the default resolvers, you can create them in /<project_root>/amplify/backend/api/<your_api_name>/resolvers. (Create this directory if it doesn't exist.)
The below are the official Amplify documentation on overriding resolvers. There is a page directly after the linked one
Let’s say you have a simple schema.graphql…
type Todo #model {
id: ID!
name: String!
description: String
}
and you want to change the behavior of request mapping template for the Query.getTodo resolver that will be generated when the project compiles. To do this you would create a file named Query.getTodo.req.vtl in the resolvers directory of your API project. The next time you run amplify push or amplify api gql-compile, your resolver template will be used instead of the auto-generated template. You may similarly create a Query.getTodo.res.vtl file to change the behavior of the resolver’s response mapping template.
https://aws-amplify.github.io/docs/cli-toolchain/graphql#overwriting-resolvers
There is also documentation on creating custom resolvers and attaching them as a custom resource. https://aws-amplify.github.io/docs/cli-toolchain/graphql#overwriting-resolvers

Resources