Skip to content

Schema Customization - Allow removing unused fields and types of input objects #3574

@gils

Description

@gils

Use case

First - I would like to take a moment to thank all the people who help maintain and support this project. Thank you!

The problem I'm dealing with is when the server generated schema contains input objects with tons of optional parameters (which could in turn have nested types) of which the application code only needs a few.

The end result is bloated generated input objects out of which only a small portion is ever needed by the application.

The trivial solution is to rewrite the query / mutation to pass only the selected parameters into the input object - which adds those parameters as variables to the generated operation.

There are a few disadvantages to the trivial approach:

  1. We don't get auto-generated code comments on the input variables
  2. The variables are coupled with the operation and can't be reused by other queries / mutations
  3. There could be nested input object types which can also contain redundant parameters. Those can't be customized at the operation level.

So the ask is to enhance the code generator configuration to allow specifying the desired fields of selected input objects. This customization can help reduce the amount of code generated where a specific application doesn't need it.

Describe the solution you'd like

Looking at https://www.apollographql.com/docs/ios/code-generation/codegen-configuration#schema-customization

One solution could be updating the fields mapping to be [String: String?] and fields with null values will be removed from the generated code.

"MyInputObject" : {
        "inputObject" : {
          "fields" : {
            "myField" : "customField",
            "bloatedField": null
          },
          "name" : "CustomInputObject"
        }
      }

If we assume bloatedField is another object which is only used in this input object - then this small change could result in multiple types not needing to be generated.

Similarly we can specify any input object we need, even when it's nested deep in the schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew addition or enhancement to existing solutions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions