Skip to content
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

Refactor ApolloExtension of FileManager #1999

Merged

Conversation

calvincestari
Copy link
Member

This is a fairly significant refactor of the ApolloExtension on FileManager. It was done with the purpose of supporting only what is needed/used in the extension of FileManager, enable mock testing, and should make it easier to remove the CLI code.

  • Replaced "folder" term with "directory", which matches the terminology of FileManager.
  • delete reduced to one method and it always calls down to the file system.
  • Renamed methods that perform a combination of logic but are named the same as single-purpose FileManager methods.
  • Reduce the API to only supports 'path' (String) operations. Paths indicate a file system which better expresses the intent of the extension.
  • Decouple FileManager from ApolloExtension to enable mocked testing.

@@ -4,118 +4,81 @@ import CommonCrypto
import ApolloUtils
#endif

/// A protocol to decouple `ApolloExtension` from `FileManager`. Use it to build objects that can support
/// `ApolloExtension` behavior.
public protocol FileManagerProvider {
Copy link
Member Author

Choose a reason for hiding this comment

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

There is brittleness to this protocol in that if the FileManager API were to change it would no longer conform but in that case we'd need to update our extension anyways.

@calvincestari calvincestari added size/medium codegen Issues related to or arising from code generation labels Oct 23, 2021
@calvincestari calvincestari added this to the Release 1.0 milestone Oct 25, 2021
var isFolder = ObjCBool(false)
let exists = base.fileExists(atPath: path, isDirectory: &isFolder)
return exists && !isFolder.boolValue
public enum PathError: Swift.Error, LocalizedError, Equatable {
Copy link
Member Author

@calvincestari calvincestari Oct 27, 2021

Choose a reason for hiding this comment

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

I don't know how I feel about this:

  • PathError is an appropriate name for the kinds of errors being returned
  • There will now be a PathError in ApolloCodegen and FileManager/MockFileManager. They share similar errors but are crafted to be specific to their scope.
  • Adding the error to the scope of the extension should be OK since it's within the apollo namespace but if the compiler takes issue with that then it'll create issues for us if FileManager natively gets PathError.

Overall I believe we need to move towards an ApolloCodegenLib scoped error enum that can encapsulate errors across all of code generation and can be extended as needed with things like recoverySuggestion, etc. For this PR however I'm inclined to leave this as-is and track the refactoring as another issue for 1.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

I created #2008 to track this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I generally have a lot of opinions on the structure of error APIs lol. It's something I nerd out on a little. So lets talk about this before starting work on #2008

Copy link
Contributor

@AnthonyMDev AnthonyMDev 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 to me

var isFolder = ObjCBool(false)
let exists = base.fileExists(atPath: path, isDirectory: &isFolder)
return exists && !isFolder.boolValue
public enum PathError: Swift.Error, LocalizedError, Equatable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I generally have a lot of opinions on the structure of error APIs lol. It's something I nerd out on a little. So lets talk about this before starting work on #2008

@calvincestari calvincestari merged commit e1bd1ce into release/1.0-alpha-incubating Oct 29, 2021
@calvincestari calvincestari deleted the 1.0/refactor-filemanager-extension branch October 29, 2021 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Issues related to or arising from code generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants