Skip to content

Prevent empty input node generation in mutation builder. #2729

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Alekhya-Polavarapu
Copy link
Contributor

@Alekhya-Polavarapu Alekhya-Polavarapu commented Jun 16, 2025

Why make this change?

Currently today when the tables has only autogenerated fileds, then the schema generation is failing with an error saying that "Empty input for create and update mutation input".
Error trace:
For more details look at the Errorsproperty.\r\n\r\n1. InputObjectCreateNewTableInputhas no fields declared. (HotChocolate.Types.InputObjectType)\r\n2. InputObjectUpdateNewTableInput has no fields declared.

#2739

What is this change?

This PR addresses the issue by conditionally generating create and update mutation input types only when the table contains at least one non-auto-generated field. This ensures that the schema remains valid and avoids generating empty input objects.

How was this tested?

  • Unit tests
  • Manual testing

screenshots

For create:

image

for update:

image

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the GraphQL mutation builders for update/patch and create operations by converting several input type generation methods to return nullable values and adding corresponding null checks. Key changes include updating method signatures to support nullable returns, inserting conditional blocks to handle cases where input types may not be generated, and adjusting related logic in both UpdateAndPatchMutationBuilder and CreateMutationBuilder.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Service.GraphQLBuilder/Mutations/UpdateAndPatchMutationBuilder.cs Updated method signatures (e.g. GenerateUpdateInputType and GetComplexInputType) and added null checks to improve null safety when generating update/patch input types.
src/Service.GraphQLBuilder/Mutations/CreateMutationBuilder.cs Updated method signatures (e.g. GenerateCreateInputTypeForRelationalDb and GenerateComplexInputTypeForRelationalDb) and added conditional checks to ensure that input objects are only used when successfully created.
Comments suppressed due to low confidence (2)

src/Service.GraphQLBuilder/Mutations/UpdateAndPatchMutationBuilder.cs:95

  • Consider defining 'inputFields' as a List rather than a List<InputValueDefinitionNode?> if null values are not expected. This change would eliminate the need to use the null-forgiving operator and improve type safety.
List<InputValueDefinitionNode> inputFieldsList = inputFields.Select(i => i!).ToList();

src/Service.GraphQLBuilder/Mutations/CreateMutationBuilder.cs:77

  • Consider updating the declaration of 'inputFields' to use a non-nullable list if null entries are not expected. This revision would remove the need for the null-forgiving operator and enhance code clarity.
inputFields.AddRange(inputFields!)

@Alekhya-Polavarapu Alekhya-Polavarapu changed the title Dev/alpolava/primarykey [Draft] Prevent empty input node generation in mutation builder. Jun 16, 2025
@Alekhya-Polavarapu
Copy link
Contributor Author

/azp

Copy link

Supported commands
  • help:
    • Get descriptions, examples and documentation about supported commands
    • Example: help "command_name"
  • list:
    • List all pipelines for this repository using a comment.
    • Example: "list"
  • run:
    • Run all pipelines or specific pipelines for this repository using a comment. Use this command by itself to trigger all related pipelines, or specify specific pipelines to run.
    • Example: "run" or "run pipeline_name, pipeline_name, pipeline_name"
  • where:
    • Report back the Azure DevOps orgs that are related to this repository and org
    • Example: "where"

See additional documentation.

@Alekhya-Polavarapu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Alekhya-Polavarapu Alekhya-Polavarapu changed the title [Draft] Prevent empty input node generation in mutation builder. Prevent empty input node generation in mutation builder. Jun 24, 2025
@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079 RubenCerna2079 added this to the Backlog milestone Jun 25, 2025
@RubenCerna2079
Copy link
Contributor

@Alekhya-Polavarapu could you update the description for the PR? I see that you wanted to create some new lines but it shows as \r\n\r\n

if (inputFields.Any())
{
List<InputValueDefinitionNode> inputFieldsList = inputFields
.Select(i => i!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the inputFields IEnumerable contains some null and some non-null fields based on if GenerateSimpleType returns null or non-null? Can we still safely cast it to ignore the null by doing i => i! ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i understand your comment correct, inputFields IEnumerable ends up with null node fields only in the case of complex object and the complex object has all fields auto generated inside of it and in that case it ends up with null and we can safely ignore those null's when creating the updateInput for original type.

otherthan that, i don't think Null's can end up in IEnumerable, even if in some edge case, it can be safely ignored.

example: i have a type publisher_PP which has only auto generated fields, i defined a relationship with Publisher_PP and Book for Publisher, and for the creaatePubliser, i do not see Publihser_PP showing up(which is getting filtered as it returned with null in the IEnumerable)

let me know if am missing anything here
realtionshipempty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The graphic you showed makes sense for the createPublisher mutation. But if you test updatePublisher workflow, updatePublisher_PP will be null, as you rightly pointed out -> it will be null if complex object has all fields auto generated inside of it.

Now isnt the following statement saying use the null updatePublisher_PP input type and other fields of the original type Publisher to convert it into a list?

List<InputValueDefinitionNode> inputFieldsList = inputFields .Select(i => i!)

I think this should instead be .Where(i => i !=null)

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but waiting for clarification on one of the comments.

@Aniruddh25
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@RubenCerna2079
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Alekhya-Polavarapu
Copy link
Contributor Author

@Alekhya-Polavarapu could you update the description for the PR? I see that you wanted to create some new lines but it shows as \r\n\r\n

thats actually part of error trace, i updated the error trace within code block

@Alekhya-Polavarapu
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@@ -194,6 +194,39 @@ type Foo @model(name:""Foo"") {
Assert.AreEqual("bar", argType.Fields[0].Name.Value);
}

[TestMethod]
[TestCategory("Mutation Builder - Create")]
public void CreateMutationExcludeIdForAllAutogeneratedFields()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a similar test for UpdateMutationExcludeIdForAllAutogeneratedFields() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i asserted the update and delete in the same test, i missed adding the correspodning test category, will add them.
please let me know if am missing anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Invalid Empty Node generation for Create and Update Mutation Input
3 participants