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

AppSync Pipeline Support w/ overriding auto-generated resolvers #867

Closed
lookitsatravis opened this issue Feb 13, 2019 · 12 comments
Closed
Labels
feature-request Request a new feature graphql-transformer-v1 Issue related to GraphQL Transformer v1

Comments

@lookitsatravis
Copy link

lookitsatravis commented Feb 13, 2019

** Which Category is your question related to? **

API - AppSync with custom stack + resolvers (#574 + #581)

** What AWS Services are you utilizing? **

AppSync Pipeline Resolver with Lambda - using @aws-amplify/cli v 1.1.0

** Provide additional details e.g. code snippets **

I've added a stack to represent a Pipeline resolver using a Lambda function as one of the data sources. During deployment, the resulting CloudFormation stack failed for the following reason:

Only one resolver is allowed per field.

I tried to update my schema.graphql to add a custom Mutation like this:

type Mutation {
  createInvitation(input: CreateInvitationInput!): Invitation
}

Which fails to push because I don't have the Amplify-generated CreateInvitationInput type. So, I added that type in manually like this:

input CreateInvitationInput {
  id: ID
  owner: String
  token: String
  invitationUserId: ID!
  acceptedAt: AWSDateTime
}

type Mutation {
  createInvitation(input: CreateInvitationInput!): Invitation
}

This also fails to push with Conflicting input type 'CreateInvitationInput' found..

So, the question is...how can I use this pipeline in place of the auto-generated resolver? I don't want to have to duplicate the input type and have a Mutation named like createInvitationCustom if I can help it. The docs indicate how to use custom VTL templates in place of the auto generated ones, and it indicates how to use a Lambda resolver with a new field, but it doesn't indicate how to replace the auto-generated VTL resolver resource with a custom one.

@UnleashedMind UnleashedMind added graphql-transformer-v1 Issue related to GraphQL Transformer v1 GraphQL documentation Add or update documentation labels Feb 13, 2019
@kaustavghosh06 kaustavghosh06 added question General question and removed GraphQL labels Feb 20, 2019
@mikeparisstuff
Copy link
Contributor

@lookitsatravis Thanks for bringing this up. I agree that this would be useful and we are looking into how to best support use cases like this. In general, we can move to a model where all resolvers are pipelines by default and any auto-generated logic will be encapsulated in reusable functions. Ideally you would be able to compose your own functions with those that are auto-generated in order to implement complex workflows for auth, auditing, etc. We have a few RFCs in development and one of them will comment on this so keep an eye out for that. I will try to remember to tag this issue when it is out.

@mikeparisstuff mikeparisstuff added the pending-response Issue is pending response from the issue author label Mar 8, 2019
@kaustavghosh06 kaustavghosh06 added feature-request Request a new feature and removed pending-response Issue is pending response from the issue author question General question labels Mar 22, 2019
@kawallis
Copy link

kawallis commented May 9, 2019

Is there any update on this issue? Me and my team are hoping to implement this

@venkatesh-kadiyala
Copy link

@mikeparisstuff
Do you have an update on this issue ?

@artista7
Copy link

@mikeparisstuff Anything?

@kaustavghosh06 kaustavghosh06 removed the documentation Add or update documentation label Jul 3, 2019
@babus
Copy link

babus commented Jul 25, 2019

@mikeparisstuff This is needed in case I assign ownerField to a custom one and want to exclude that field from the Input type so that the mutation works without passing that ownerField and auto assigned by the identifyField. Right now, I'm remvoing that field from the Input type in the AWS Console Schema editor. But it gets overridden everytime I amplify push.

@babus
Copy link

babus commented Sep 15, 2019

@mikeparisstuff Any update on this? It's been a long since this has been reported. I am not seeing any progress in this one. Consider this model,

type UserDevice
    @model
    @auth(rules: [
      { allow: owner, ownerField: "userDeviceUserId", identityField: "sub" }
    ])
    @key(fields: ["userDeviceUserId", "deviceKey"])
{
    deviceKey: String!

    userDeviceUserId: String!
    user: User @connection(name: "UserDevices")

    isActive: Int

    createdAt: String
    updatedAt: String
}

I don't want the userDeviceUserId to be passed by the user due to security reasons. This needs to be auto assigned with the value of the current user sub. String! is needed because I get InvalidDirectiveError: The primary @key on type 'UserDevice' must reference non-null fields. error if I remove !. If I leave it that way, I get required userDeviceUserId on calling create mutation. The resolver has been generated to assign the user sub though. This is a clear conflict of requirements.

Update: If I pass userDeviceUserId with a value other than the current user sub, I am getting "Not Authorized to access createUserDevice on type UserDevice" error which I guess is not allowing records to be created with other user ids. So, we can consider this as partially resolved but a better documentation could have saved a lot of time.

@paulnolan7
Copy link

@mikeparisstuff Is there a way to disable the type check, as I need to bring up and maintain about 40 input type from the build output schema.graphql to the source schema.graphql file. It will be very difficult to maintain these. It would be good to disable the check on codegen because the types are all there in the build schema.graphql. It's just the pre check before the build.
This could work as a short term fix until the properly solution is available.

@matmedsaid
Copy link

@mikeparisstuff Any update on this? It's been a long since this has been reported. I am not seeing any progress in this one. Consider this model,

type UserDevice
    @model
    @auth(rules: [
      { allow: owner, ownerField: "userDeviceUserId", identityField: "sub" }
    ])
    @key(fields: ["userDeviceUserId", "deviceKey"])
{
    deviceKey: String!

    userDeviceUserId: String!
    user: User @connection(name: "UserDevices")

    isActive: Int

    createdAt: String
    updatedAt: String
}

I don't want the userDeviceUserId to be passed by the user due to security reasons. This needs to be auto assigned with the value of the current user sub. String! is needed because I get InvalidDirectiveError: The primary @key on type 'UserDevice' must reference non-null fields. error if I remove !. If I leave it that way, I get required userDeviceUserId on calling create mutation. The resolver has been generated to assign the user sub though. This is a clear conflict of requirements.

Update: If I pass userDeviceUserId with a value other than the current user sub, I am getting "Not Authorized to access createUserDevice on type UserDevice" error which I guess is not allowing records to be created with other user ids. So, we can consider this as partially resolved but a better documentation could have saved a lot of time.

Hello guys, can you please tell me how did you fix the issue?

@hackrx
Copy link

hackrx commented Nov 10, 2021

@matmedsaid did you find a fix to this issue? I am facing kind of similar issue, but in my case, I want to change the input type of autogenerated mutation for eg.
deleteBlog takes id as input (by default) but I want input to be {blogID, userID,etc}, so I edited Schema.graphql

input DeleteBlogInput {
  blogID: ID!
  userID: ID!
  id: ID!
}
type Mutation{
deleteBlog(input: DeleteBlogInput): Like @aws_iam @aws_api_key
}

I also created Mutation.deleteBlog.req.vtl and Mutation.deleteBlog.res.vtl according to my input varialbes inside resolvers folder.
Please help me, if I am missing something.
Thanks.

@hackrx
Copy link

hackrx commented Nov 10, 2021

I am able to solve this issue, read more

type Blog
@model( @model(
    mutations: { create: "createBlog", update: "updateBlog", delete: null }
  ))
{
...
}

input DeleteBlogInput {
  blogID: ID!
  userID: ID!
  id: ID!
}
type Mutation{
deleteBlog(input: DeleteBlogInput): Like @aws_iam @aws_api_key
}

And it worked like a charm. Cheers 🥂

@renebrandel
Copy link
Contributor

Hi folks - a couple of things. The original issue required function pipeline resolvers, you can chain them as such: https://docs.amplify.aws/cli/graphql/custom-business-logic/#chaining-functions
With the new GraphQL transformer, every Amplify-generated resolver is now a pipeline resolver. So you could add to them, slot in your own custom logic and more. Or, can also create your own custom VTL resolvers.

Useful docs:

@-mention me if this is still an issue otherwise I'll leave this closed for now.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature graphql-transformer-v1 Issue related to GraphQL Transformer v1
Projects
None yet
Development

No branches or pull requests