-
Notifications
You must be signed in to change notification settings - Fork 79
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
Allow for input type in custom mutation definition #2734
Comments
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂 |
Hi @travishaby thanks for raising this issue. While we support setting arguments for custom mutations that generate input types in the compiled schema, it seems you are asking for something more robust that supports nested input types. Can you please explain a bit more how you would like this feature to work? Could you provide an API example? For now, I will mark this as a feature request for the team to consider. |
Hi @chrisbonifacio ! Sorry for the delay--here's an example of a valid graphql schema that I would like to see support for that currently doesn't seem possible. Happy to be wrong if this is supported! input ProgramInput {
parentId: ID!
active: Boolean!
# nested input type is the key thing that doesn't seem supported
requirements: ProgramRequirementsInputType
}
input ProgramRequirementsInputType {
createdAt: AWSDateTime
minCollegeCredits: Int
minCollegeCreditsDetails: String
updatedAt: AWSDateTime
}
createProgram(programData: ProgramInput!): ProgramType in the Gen2 definition api, i would expect to be able to do something like... const schema = a.schema({
// ...
ProgramInput: a.customInputType({
parentId: a.id(),
active: a.boolean().required(),
requirements: a.ref('ProgramRequirementsInputType'),
}),
ProgramRequirementsInputType: a.customInputType({
// ...
}),
createProgram: a
.mutation()
.arguments({
programData: a.ref('ProgramInput')
})
.returns(a.ref('ProgramType'))
.authorization((allow) => allow.authenticated('oidc'))
.handler(
a.handler.custom({
entry: './resolvers/createProgram.js',
dataSource: 'CreateProgramDataSource',
}),
// ...
), |
ah, almost forgot! just to call it out explicitly, would also want to do an array of an input type like: // ...
const schema = a.schema({
// ...
ProgramInput: a.customInputType({
parentId: a.id(),
active: a.boolean().required(),
requirements: a.ref('ProgramRequirementsInputType').array(),
}),
// ... |
I'm having problems here too.
In my frontend i have the case where i only update single fields at once. By not having an input type i have to define a separate GraphQL document for each field i want to update with just that argument present (for example UpdateForumNameMutation.graphql, UpdateForumKeyMutation.graphql, UpdateForumDescriptionMutation.graphql, etc.). Coming from Amplify Gen 1 i was able to define an input type with all of the fields nested underneath with just one GraphQL document for updateForum in my frontend where i am able to just not pass the field i don't want to update.
|
Another use-case that is currently not supported is that of filter input types. All auto-generated queries have a filter argument as shown below and it is currently not possible to something similar with custom queries in Gen 2 since we can't define/use input types and nest them.
|
Just to add to this.... I'm not sure how to even get the auto generated types from the schema: Would expect something like:
But Schema doesn't include the Input Types. |
Can we expect this feature in future versions? |
Hey all, we're currently working on adding support for custom types and refs in custom query/mutation arguments. GraphQL Input types will be automatically generated from these behind the scenes. We'll post an update here as soon as the feature is released. |
Thanks for the update. I‘m eagerly awaiting this feature since this is a blocker for me. |
@iartemiev Are you working on adding support for custom types and refs in custom query/mutation arguments as well as return types? |
Environment information
Description
It doesn't look like the Gen2 data construct provides the ability to declare an input type when creating a mutation.
I have a fairly complex object that I'm trying to pass in to write a record, and an input type that accepted nested input types would be ideal in order to keep the schema DRY and make things clearer.
Thanks!
The text was updated successfully, but these errors were encountered: