aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
764 stars 221 forks source link

AWS Amplify Project in IntelliJ #2429

Open jmbarroso opened 3 years ago

jmbarroso commented 3 years ago

Your Environment

Question

I have an AWS Amplify project; I started creating the backend based on graphQL and Lambda (Java Runtime). I found that the IDEA project is not set up to load Source folders or Gradle config. E.g., Java Lambda Src folders are not detected as Source; if the src folder is flagged as Source manually, the import fails because classes are not found, so new functions have to be imported manually as modules, @model or @auth annotations from AWS Amplify are not detected by IDEA and are shown as errors.

The question is, how should I set up IDEA to run an AWS Amplify project with Java runtime for Lambdas so it automatically picks up new lambdas and understands Amplify GraphQL annotations?

abrooksv commented 3 years ago

Was there a guide or blog post you followed to create the project?

jmbarroso commented 3 years ago

No, I set up IDEA with the AWS Toolkit plugin following instructions, then followed the simple examples for the AWS amplify framework using Amplify CLI docs.

Steps I followed:

  1. Configured Amplify following https://docs.amplify.aws/start/getting-started/installation/q/integration/react#install-and-configure-the-amplify-cli
  2. Created basic CRUD using dynamo. I followed https://docs.amplify.aws/cli/graphql-transformer/overview
  3. Added some Functions using Java runtime. Followed-ish this guide: https://docs.amplify.aws/cli/graphql-transformer/function

Thanks!

abrooksv commented 3 years ago

Do you have a Gradle file already? If so, you should be able to right click it and select Import Gradle Project.

jmbarroso commented 3 years ago

The Gradle file is the one generated by the amplify command. I did that, and it solved the problem. My question was to understand how the AWS Toolkit handles the IntelliJ config for Amplify projects.

So, I understand that as I generate functions and other artifacts with Amplify CLI, I have to import those manually into IDEA. Let me know if it is not correct.

Some specific questions:

Thanks!

abrooksv commented 3 years ago

We have not looked into integrating Amplify into the AWS Toolkit yet so it is still a manual process.

jmbarroso commented 3 years ago

Ok thanks.

Any manual way to fix the errors with the GraphQL annotations and debug mock API ?

Sent from my iPhone

On Feb 9, 2021, at 6:38 PM, Austin Brooks notifications@github.com wrote:

 We have not looked into integrating Amplify into the AWS Toolkit yet so it is still a manual process.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

jmbarroso commented 3 years ago

@abrooksv is there any way to manually fix the errors in IDEA coming from annotations?

abrooksv commented 3 years ago

I am not sure, I have never used the feature myself

codified-likeness-utility commented 2 years ago

Is there an update on this? I would love to be able to use Webstorm or IntelliJ over VSCode for my Amplify projects

waltmayfield commented 4 months ago

For a manual fix, try adding file with the contents below to your project. Then add a reference to it in the graphql.config.yml file.

For example if you save it as _aws.graphql, update the graqhql.config.yml file with a second schema. ex: schema:

_aws.graphql

# @model directive - Defines top level object types in your API that are backed by Amazon DynamoDB
directive @model on OBJECT

# @primaryKey directive - Configures custom primary key for @model types
directive @primaryKey(fields: [String!]!) on OBJECT | FIELD_DEFINITION

# @index directive - Configures custom secondary index structures for @model types
directive @index(name: String, sortKeyFields: [String!]) on OBJECT | FIELD_DEFINITION

# @auth directive - Defines authorization rules for your @model types and fields
directive @auth(rules: [AuthRule!]) on OBJECT | FIELD_DEFINITION
input AuthRule {
    allow: AuthStrategy!
    provider: AuthProvider
    ownerField: String
    identityClaim: String
    groupClaim: String
    groups: [String]
    groupsField: String
    operations: [ModelOperation]
}

enum AuthStrategy {
    owner
    groups
    private
    public
}

enum AuthProvider {
    apiKey
    iam
    oidc
    userPools
}

enum ModelOperation {
    create
    update
    delete
    read
}

# @hasOne directive - Create a one-directional one-to-one relationship between two models
directive @hasOne(fields: [String!]) on FIELD_DEFINITION

# @hasMany directive - Create a one-directional one-to-many relationship between two models
directive @hasMany(indexName: String, fields: [String!]) on FIELD_DEFINITION

# @belongsTo directive - Use a "belongs to" relationship to make a "has one" or "has many" relationship bi-directional
directive @belongsTo(fields: [String!]) on FIELD_DEFINITION

# @manyToMany directive - Configures a "join table" between two models to facilitate a many-to-many relationship
directive @manyToMany(relationName: String) on FIELD_DEFINITION

# @function directive - Configures a Lambda function resolvers for a field
directive @function(name: String!) on FIELD_DEFINITION

# @http directive - Configures an HTTP resolver for a field
directive @http(url: String!, method: HttpMethod) on FIELD_DEFINITION
enum HttpMethod {
    GET
    POST
    PUT
    DELETE
    PATCH
}

# @predictions directive - Queries an orchestration of AI/ML services such as Amazon Rekognition, Amazon Translate, and/or Amazon Polly
directive @predictions(actions: [PredictionsActions!]!) on FIELD_DEFINITION
enum PredictionsActions {
    identifyText
    identifyLabels
    translateText
    convertTextToSpeech
    convertSpeechToText
}

# @searchable directive - Makes your data searchable by streaming it to Amazon OpenSearch
directive @searchable on OBJECT

# @mapsTo directive - Specifies the original name of a table that contains production data that cannot be deleted
directive @mapsTo(name: String!) on FIELD_DEFINITION