-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
My hope is that we can get this working behind e.g. a feature flag and at least ship to everyone on our team. I'll try to figure out if this is possible or not |
I'll think about this some more. For reading existing comments, it should be easy for us to support placing the comments in the right locations on modified files (for now, we can do this by sending the code in your editor to the sourcegraph server. In the future, before we ship to any real users, this would be done client side using the same line resolution logic). For creating new comments, the biggest risk is probably just making sure that we clearly denote "I am commenting on some modified code" in the DB so we don't end up with a lot of garbage that we later need to filter out somehow on web. I'll think of how to do this. |
The GitHub Pull Requests extension got published with proposed api, so unsure if they got a special exception or if we just need to mark our extension as preview |
src/graphql.ts
Outdated
@@ -0,0 +1,70 @@ | |||
'use strict' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/rant GraphQL is supposed to be nicer than REST and gRPC but then you end up having to copy code like this all around the place and end up having to write your own functions to do fetches like replyToCommentThread
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont have to copy paste this code. We could share it. Some things in here are also unneeded, like the symbol-backed gql tag.
We could generate functions for queries and mutations, but if you need to specify what fields you want
I will push a commit to unify some of the GraphQL logic here to share it a bit more with https://github.com/sourcegraph/sourcegraph-extension-discussions |
sourcegraph/sourcegraph#13253 will address the whole repo resolution issue, will push a change here soon to implement it on this end |
cp ../sourcegraph-extension-discussions/src/typings/SourcegraphGQL.d.ts src/typings/SourcegraphGQL.d.ts
I am not sure I agree with the "shared" code introduced in 246b109. For one thing, the extension is now broken (will investigate). I would prefer to revert that change unless you actually want to split it into a shared dependency (which I would still have some concerns with). The proverb "a little bit a copying is better than a little bit of dependency" comes to mind. |
I agree, the reason GraphQL clients are usually not generated is that the GraphQL query language itself is seen as the "interface" or "SDK" for APIs. A folder that must be kept in sync sounds like it causes more trouble than it offers benefits. |
It's not broken for me. What is broken for you?
I agree, that sucks. It is code copied from our main repo. However, before this change I was receiving arbitrary errors such as:
With no information about what errors the GraphQL endpoint actually returned. And debugging this wasn't trivial for me because the error handling implementation was 100% different than the other two implementations.
The vast majority of GraphQL fields included here are:
There are now three separate TypeScript clients (web app, Sourcegraph Extension, VS Code extension) that:
In what amounts to a few hundred lines of non-trivial code that can be messed up easily in each client IMO. From my perspective, I have trouble seeing this as anything other than the most perfect use case for sharing code.. but maybe I just don't understand "the GraphQL way" and copying code here is better. I am happy to concede here. |
cc @dadlerj who worked on GraphQL error handling |
{ input, relativeRev } | ||
) | ||
if (!data || !data.discussions || !data.discussions.createThread) { | ||
throw createAggregateError(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have nicer error handling now using dataOrThrowErrors
! See https://sourcegraph.sgdev.org/github.com/sourcegraph/sourcegraph/-/blob/src/backend/graphql.tsx#L21:17 and examples in https://sourcegraph.sgdev.org/github.com/sourcegraph/sourcegraph/-/commit/78e0791ca3e3d4ac37d13b38c6da84473cb6c4e5
opts | ||
) | ||
if (!data || !data.discussionThreads) { | ||
throw createAggregateError(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
!data.discussionThreads.nodes || | ||
data.discussionThreads.nodes.length !== 1 | ||
) { | ||
throw createAggregateError(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
{ threadID, contents, relativeRev } | ||
) | ||
if (!data || !data.discussions || !data.discussions.addCommentToThread) { | ||
throw createAggregateError(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
{ markdown } | ||
) | ||
if (!data || !data.renderMarkdown) { | ||
throw createAggregateError(errors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
I've thought about this a lot more over the past few hours. Here is my final conclusion / stance on the topic:
But, I strongly dislike the fact that we have separate error handling and GraphQL request code that is copied, sprinkled, and modified throughout several of our codebases, and Dan's feedback above just re-enforces my stance here that it is impossible to know which file to copy. To be specific, why does the browser extension still use
I think this is a problem worth solving before we merge this PR for the following reasons:
|
I agree that it's not good that these are copied everywhere. We have a lot of copy-pasted code, I've been working on sharing more, and GraphQL copied query functions were always minor compared to things like hover tooltip code. They are literally tiny HTTP request functions. It's easy to copy, not as easy to come up with the right abstraction. For example, how do you even write a query function, that works both in webapp/browser extension, but also in NodeJS, without relying on platform-specific API like |
There are also open source solutions out there that we could and probably should use. I will just need some time to evaluate them. |
The short answer is: I don't know. I don't have the answers here. I am just calling out what is from my perspective a major pain point in using GraphQL in our codebase, that I feel should be easily addressable somehow.
|
I am getting this graphql error: "invalid graphql.ID" when creating a new thread.
|
The bulk of this file is requestGraphQL, which is not copied because I had to make it work in a node environment. The convenience functions and gql tag were copied, but there is not much there.
I spent no time thinking about or dealing with edge/error cases (this was hack quality). I suspect it will be hard to share error code because the right way to treat errors in a VS Code extension may be different than web. |
@nicksnyder Odd, that must mean that the |
@nicksnyder that's totally fair :) I just feel we gotta get error handling working properly before merging this |
I am running sourcegraph/enterprise, do I need to run sourcegraph/sourcegraph? |
no, you should run |
Oops, this was my problem 😬 |
Moving to #19 |
This is not mergeable for a few reasons: