Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Use GraphQL for Pull Request Models. - #1712

Merged
grokys merged 19 commits into
masterfrom
refactor/pr-models
Jun 21, 2018
Merged

Use GraphQL for Pull Request Models.#1712
grokys merged 19 commits into
masterfrom
refactor/pr-models

Conversation

@grokys

@grokysgrokys commented May 31, 2018

Copy link
Copy Markdown
Contributor

Description

Previously we were using a mix of REST and GraphQL for Pull Requests and Pull Request Reviews, and our data model didn't fit either very well. This PR:

  • Adds a PullRequestDetailModel which is modeled after what we're hoping will be the future shape of the GraphQL pull request/reviews API
  • Moves reading pull request details out of ModelService and into PullRequestSession - this is now the only place to get hold of a PR details model. Doing this means that all parts of the extension always agree about the state of a pull request, and prevents some unnecessary API reads that we were carrying out before - our UI should feel a lot snappier now!
  • Reads PullRequestDetailModel using GraphQL. Because the GraphQL API for reviews and comments isn't complete yet, after reading this we massage the model into what should be the final shape after reading (see BuildPullRequestThreads

The old PullRequestModel is still there (although in a cut-down form) and still read using REST. It is now used just for the PR list. This will be moved to GraphQL in a later PR.

Testing

Basically, everything around pull requests/reviews/comments should work as before!

TODO

grokys added 7 commits May 31, 2018 15:32
Now using a data model based on GraphQL (or at least a hypothetical future version of the GraphQL API based on conversations with that team).
Should really be using `ActorAvatarView` here but our mess of assemblies means that it'd have to be moved. Fix later.
Don't do this. It makes all PRs get returned with the same number.
If the basic logic doesn't work, likely the data is bad.
...`PullRequestUserReviewsViewModelTests`. The view now loads instantly :D
@grokysgrokys added the WIP label May 31, 2018
grokysand others added 3 commits June 1, 2018 11:40
Mainly merging #1701
Conflicts:
src/GitHub.Exports.Reactive/Services/IPullRequestSession.cs
src/GitHub.InlineReviews/SampleData/CommentThreadViewModelDesigner.cs
src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs
src/GitHub.InlineReviews/Services/PullRequestSession.cs
src/GitHub.InlineReviews/Services/PullRequestSessionService.cs
src/GitHub.InlineReviews/ViewModels/CommentThreadViewModel.cs
src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs
src/GitHub.InlineReviews/ViewModels/ICommentThreadViewModel.cs
test/GitHub.InlineReviews.UnitTests/ViewModels/PullRequestReviewCommentViewModelTests.cs
Because adding e.g. a PR review comment affects both the `PullRequestReviewModel` _and_ the `PullRequestDetailModel`, re-read the PR when a comment mutation is executed.
@grokysgrokys changed the title WIP: Refactoring Pull Request Models.Refactoring Pull Request Models.Jun 12, 2018
@grokys
grokysforce-pushed the refactor/pr-models branch from 4bdfc55 to e849c1bCompareJune 12, 2018 15:21
The placeholder should be in `Editing` state when it is shown.
{
public NewInlineCommentThreadViewModelTests()
{
Splat.ModeDetector.Current.SetInUnitTestRunner(true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should probably move this into an assembly wide setup for the whole test assembly. This is possible with NUnit in a way it wasn't with xUnit.

For example we could move it into AssemblyInfo.cs like this:

Splat.ModeDetector.Current.SetInUnitTestRunner(true);

Otherwise it's too easy to forget and end up with hanging or not depending on the order they're executed. 😨

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alternatively we could do this as part of #1721, which I think would make more sense. 😉

@jcansdalejcansdale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like how you've cleaned up the models. :-) Just a few questions, no blockers.

{ string.Empty, new PullRequestDirectoryNode(string.Empty) }
};

await Task.Delay(0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the Task.Delay(0) for? Would this behave the same with Task.Yield()?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Oops, that was left in from when I commented out the whole of the method. Putting a Task.Delay(0) in was my way of preventing the "method doesn't use await" error. Will remove.

if (readPullRequest == null)
{
readPullRequest = new Query()
.Repository(Var(nameof(owner)), Var(nameof(name)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm curious why you're caching the compiled query here but not other queries? I've found an easy way to automatically handle the named arguments and caching if this is something users of GraphQL should be doing.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Basically just because this was written from scratch and the other queries were just modified. We should probably be doing the same with the other queries, not sure if that should be in this PR or another?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can I show you my GraphQL prototype before we do the the same with the other queries? I'd like to find out if you think it's a good idea in principle before developing it any further. So maybe push this to another PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wanted to get your thoughts on this:
octokit/octokit.graphql.net#104

<d:DesignData.DataContext>
<vm:PullRequestReviewSummaryViewModel Id="1" State="Pending" FileCommentCount="2">
<vm:PullRequestReviewSummaryViewModel.User>
<!--<vm:PullRequestReviewSummaryViewModel.User>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this commented out for a reason?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed.

@jcansdalejcansdale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There seems to be an issue when attempting to leave comments on some files.

image

Above I'm attempting to leave a comment on the following line of this PR:
https://github.com/jcansdale/VisualStudio/blob/df6aa658a185620d61e3398656871cf27c3ae02f/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewCommentViewModel.cs#L66

@grokys

Copy link
Copy Markdown
ContributorAuthor

@jcansdale are you sure this was caused by this PR? This doesn't look like anything that this PR should have changed. Can you leave a comment in the same position on master?

@meaghanlewis

Copy link
Copy Markdown
Contributor

@grokys@jcansdale I just tried to leave a comment in the same position on master and I do see this same error happening.

@jcansdalejcansdale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry about the position is invalid false alarm!

This PR looks good. 👍

@meaghanlewismeaghanlewis added this to the 2.5.4 milestone Jun 14, 2018
 Conflicts:
src/GitHub.Exports.Reactive/Services/IPullRequestSession.cs
src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs
src/GitHub.InlineReviews/Services/PullRequestSession.cs
src/GitHub.InlineReviews/Services/PullRequestSessionService.cs
src/GitHub.InlineReviews/ViewModels/InlineCommentThreadViewModel.cs
test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs
test/GitHub.InlineReviews.UnitTests/ViewModels/InlineCommentThreadViewModelTests.cs
@grokys
grokys merged commit d5ddf0d into masterJun 21, 2018
@grokysgrokys changed the title Refactoring Pull Request Models.Use GraphQL for Pull Request Models.Jul 10, 2018
@grokysgrokys mentioned this pull request Jul 10, 2018
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@grokys@meaghanlewis@jcansdale