eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
51 stars 12 forks source link

[FEAT] Option to skip generating some resolvers #216

Closed lensbart closed 10 months ago

lensbart commented 10 months ago

Hello,

When running the server preset plugin, some of the created resolvers are redundant. For example, for the following schema:

type Something {
  value: String
}

input DeleteSomethingInput {
  value: String
}

type DeleteSomethingPayload {
  somethingId: ID!
}

union DeleteSomethingResult =
  DeleteSomethingPayload
  | InvalidInputError
  | NotAllowedError
  | NotFoundError

extend type Mutation {
  deleteSomething(input: DeleteSomethingInput!): DeleteSomethingResult!
}

In this example, DeleteSomethingPayload only appears as a union member of the return type of deleteSomething, and will always include all of its scalar properties via the return value of the deleteSomething mutation resolver.

This plugin will create a separate resolver for CreateSomethingPayload as well. Due to my codebase conventions, this resolver is redundant. Would it be possible to include a config option to:

  1. avoid creating resolvers for object types that match a certain suffix (or regex)?
  2. enforce all object fields to be present for these types (because they don’t have a corresponding resolver)

Or is there a different/better approach to achieve the desired effect?

Many thanks in advance!

lensbart commented 10 months ago

Closing because I realised I should simplify my schema instead (in the example above: removing the DeleteSomethingPayload type and replacing it in the response with Something)