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

Fixing fragment definition generation when not generating operation definitions #218

Merged
merged 4 commits into from Jan 16, 2024

Conversation

BobaFetters
Copy link
Member

Only generate definitions in fragment files if the 'operationDocumentFormat' config contains the 'definition' value.

Closes apollographql/apollo-ios#3282

Only generate definitions in fragment files if the 'operationDocumentFormat' config contains the 'definition' value.
@BobaFetters BobaFetters self-assigned this Jan 3, 2024
@BobaFetters BobaFetters requested a review from a team as a code owner January 3, 2024 07:24
Copy link

netlify bot commented Jan 3, 2024

Deploy Preview for eclectic-pie-88a2ba ready!

Name Link
🔨 Latest commit 5245fae
🔍 Latest deploy log https://app.netlify.com/sites/eclectic-pie-88a2ba/deploys/65a6f4a527c1030008536de9
😎 Deploy Preview https://deploy-preview-218--eclectic-pie-88a2ba.netlify.app/technotes
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

I'm confused how the tests are passing here. fragmentDefinition is a requirement of the Fragment protocol, so generating a fragment without this property should make it not conform to the Fragment protocol.

@BobaFetters
Copy link
Member Author

I'm confused how the tests are passing here. fragmentDefinition is a requirement of the Fragment protocol, so generating a fragment without this property should make it not conform to the Fragment protocol.

@AnthonyMDev Going to assume it has to do with it just doing string comparison of what gets generated, more tests would still need to be added to cover actual compilation before this patch would be ready to go.

Mainly got this up so we could have a discussion about how/if we wanted to handle this

@AnthonyMDev
Copy link
Contributor

Ah I see. Yes, I do think this is the right approach. We don't need to separate configuration option for disabling fragment definitions, it should use the operationDocumentFormat as you've done here.

We just need to figure out the right way to make this compile. We could make the Fragment protocol have a default implementation of fragmentDefinition that is just an empty String so we don't break backwards compatibility I guess?

The Codegen Test Configurations CI job actually generates the code, compiles a project using it and runs some tests. So maybe we need to add a configuration there that has this option turned off.

@BobaFetters
Copy link
Member Author

Ah I see. Yes, I do think this is the right approach. We don't need to separate configuration option for disabling fragment definitions, it should use the operationDocumentFormat as you've done here.

We just need to figure out the right way to make this compile. We could make the Fragment protocol have a default implementation of fragmentDefinition that is just an empty String so we don't break backwards compatibility I guess?

The Codegen Test Configurations CI job actually generates the code, compiles a project using it and runs some tests. So maybe we need to add a configuration there that has this option turned off.

Yea I think a default implementation for fragmentDefinition would be the right approach. I will go ahead and do that and then work on adding more tests to help cover compilation.

-Adding default fragment protocol implementation
-Adding codegen configuration test to validate compilation
@@ -13,7 +13,8 @@
},
"pruneGeneratedFiles" : true,
"queryStringLiteralFormat" : "multiline",
"warningsOnDeprecatedUsage" : "include"
"warningsOnDeprecatedUsage" : "include",
"operationDocumentFormat" : ["operationId"]
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to address this in this current PR. But for integration testing individual configuration options, maybe we could build something better here.

We need to have these multiple different project setups in TestCodeGenConfigurations for testing the actual project configurations (Cocoapods, SPM, Xcode) and codegen methods (Relative vs absolute, schema module embedded, etc).

These are things that affect how/where the files are generated and if they include the correct namespacing and import statements to link and compile properly.

But for testing other individual configuration properties which would be the same regardless of these configurations, we should probably have a single project that we re-generate with different configurations so that we can isolate and test just the configuration options we want to test. These could be done using the Swift Scripting codegen to make it easier to run multiple of them rapidly.

This will take some time to set up properly, so it's not something I think we need to do right now. But this isn't the first time I've noticed that we are kind of overloading these integration tests, so it might be worth thinking about.

/// Extension providing default implementation for the ``Fragment`` protocol.
extension Fragment {
// Default implementation for the `fragmentDefinition` variable
static var fragmentDefinition: StaticString {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be public?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the failing CI test is because of this actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does indeed, forgot to mark it public

@BobaFetters BobaFetters merged commit b91352e into main Jan 16, 2024
19 checks passed
@BobaFetters BobaFetters deleted the fix/fragment-definition-generation branch January 16, 2024 21:51
BobaFetters added a commit to apollographql/apollo-ios that referenced this pull request Jan 16, 2024
BobaFetters added a commit to apollographql/apollo-ios-codegen that referenced this pull request Jan 16, 2024
BobaFetters pushed a commit that referenced this pull request Jan 16, 2024
79dbcd0 Fixing fragment definition generation when not generating operation definitions (#218)

git-subtree-dir: apollo-ios
git-subtree-split: 79dbcd0
BobaFetters pushed a commit that referenced this pull request Jan 16, 2024
…hen not generating operation definitions

git-subtree-dir: apollo-ios
git-subtree-mainline: 65df595
git-subtree-split: 79dbcd0
BobaFetters pushed a commit that referenced this pull request Jan 16, 2024
45b05486 Fixing fragment definition generation when not generating operation definitions (#218)

git-subtree-dir: apollo-ios-codegen
git-subtree-split: 45b054866bb3307b3b941dcf62dff144a706599c
BobaFetters pushed a commit that referenced this pull request Jan 16, 2024
…ration when not generating operation definitions

git-subtree-dir: apollo-ios-codegen
git-subtree-mainline: ed0f372
git-subtree-split: 45b054866bb3307b3b941dcf62dff144a706599c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants