codecov / engineering-team

This is a general repo to use with GH Projects
1 stars 1 forks source link

Investigation - propose pattern for GraphQL resolvers #2598

Open suejung-sentry opened 1 month ago

suejung-sentry commented 1 month ago

The current patterns in our GraphQL resolvers pass arguably inconsistent or ambiguous objects as the first (0th) positional argument meant to represent the "parent" per the GraphQL convention.

This ticket represents work to set standards on questions like:

As an example, here is repositoryConfg's field resolvers whose "parent" type is the database model from shared and contains the entire database object passed from parent (repository) to child (repositoryConfig). Confusingly, the parent repository resolver's "parent" type here takes the same type as an input.

I'd argue that we place too much of a burden on developers to have deep knowledge of the codebase (and graphQL) before they can change one line of code in any resolver - would be nice to see how we can leverage types and/or better names to help reduce this and let anyone jumping in be able to draw a line from A to B without having implicit knowledge about chains of resolvers and where any ancestor has placed information into its return value ("parent") or Any-typed "context" that results in a "leap of faith".

Definition of done - proposed pattern + doc we can agree on to start implementing for net new models and have a plan for migrating the old ones to the new pattern, if needed. At a minimum, root out the "bad apples" (i.e., instances of "improper" patterns), so new developers can assume the code is written to graphql/our standard.

Background / a proposed option - https://github.com/codecov/codecov-api/pull/806#discussion_r1772393338

Some possible low-hanging fruit:

suejung-sentry commented 1 month ago

A possible place I can try it out here - https://github.com/codecov/codecov-api/pull/847/files with command = info.context["executor"].get_command("commit")