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

Fix: broken namespace aliases and mutable selections #108

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

gmac
Copy link
Contributor

@gmac gmac commented Nov 12, 2021

Fixes some problems with namespace operations in the query planner, and simplifies the overall logic in the process.

Problems + Fixes

query {
  boo: myNamespace {
    product {
      name
    }
    manufacturer {
      name
    }
  }
}
  • The namespace handler condition was demonstrably broken by field aliases: it composed its insertion point using field Name rather than Alias. This issue is now fixed.

  • The namespace condition could also corrupt the user's original selection because it modified fields directly rather than making copies. This was problematic because it modified the selection used to filter the final result, as described in Filtering base interface selections is not type-aware #106. This is also fixed.

  • With the above adjustments made, the namespace condition ended up basically identical to the normal composite field handler. So, this simplifies the logic so that a failed location lookup now just flows into the normal field handlers; this new pattern has the added advantage of handing both leaf values and composite fields.

Resolves #106 by happy accident.

@gmac gmac requested a review from a team as a code owner November 12, 2021 03:22
@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2021

Codecov Report

Merging #108 (81cb6ac) into main (e0e24cc) will increase coverage by 0.81%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   67.67%   68.48%   +0.81%     
==========================================
  Files          24       24              
  Lines        2738     2618     -120     
==========================================
- Hits         1853     1793      -60     
+ Misses        734      690      -44     
+ Partials      151      135      -16     
Impacted Files Coverage Δ
plan.go 83.78% <100.00%> (+0.30%) ⬆️
format.go 86.84% <0.00%> (+19.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0e24cc...81cb6ac. Read the comment docs.

@lucianjon
Copy link
Contributor

lucianjon commented Nov 15, 2021

Thanks @gmac, looks like an improvement on what we had. I'd like to refactor that whole piece at some point, as assuming the error is actually not an error makes the conditions read quite weird. That would require another way to figure out the field requested is a namespace, which I'm sure is possible but just requires some thinking.

For now would you mind chucking a comment in the else case to say the error is ignored as it's assumed to be a namespace if err != nil. Just to make sure someone else coming along doesn't think the error is unintentionally ignored. We're still ignoring some potential actual errors but I think it's the best that can be done for now and the query validation should be catching the bulk of those.

@gmac gmac force-pushed the fix-namespace-alias branch from b870bbc to 81cb6ac Compare November 16, 2021 01:10
@gmac
Copy link
Contributor Author

gmac commented Nov 16, 2021

@lucianjon – comment added! I had the same thought about that error line, the logic is weird and goes against the grain of exceptions being exceptional. For a refactor, I've sort of been thinking that the isBoundary map could become more robust with other useful type information, for example:

FederationObjects: {
  MyNamespace: { Kind: "namespace", Implementations: nil },
  MyBoundary: { Kind: "boundary", Implementations: nil },
  MyInterface: { Kind: "interface", Implementations: ["MyBoundary"] },
}

That kind of structure would be able to distinguish boundaries and namespaces, and would provide a pre-compiled cache of all abstract boundaries so that they wouldn't have to be enumerated repeatedly.

@lucianjon
Copy link
Contributor

@lucianjon – comment added! I had the same thought about that error line, the logic is weird and goes against the grain of exceptions being exceptional. For a refactor, I've sort of been thinking that the isBoundary map could become more robust with other useful type information, for example:

FederationObjects: {
  MyNamespace: { Kind: "namespace", Implementations: nil },
  MyBoundary: { Kind: "boundary", Implementations: nil },
  MyInterface: { Kind: "interface", Implementations: ["MyBoundary"] },
}

That kind of structure would be able to distinguish boundaries and namespaces, and would provide a pre-compiled cache of all abstract boundaries so that they wouldn't have to be enumerated repeatedly.

Wicked cheers, will get this in. Yeah agreed on the refactor, we have access to all the information we need when we merge schemas and could easily just keep it all stored on there. Can write an issue up for it or if you'd like to, go for it!

@lucianjon lucianjon merged commit 4b3dd2e into movio:main Nov 16, 2021
@gmac gmac deleted the fix-namespace-alias branch November 16, 2021 02:51
@gmac
Copy link
Contributor Author

gmac commented Nov 16, 2021

@lucianjon#113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filtering base interface selections is not type-aware
3 participants