Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 2388317

Browse files
authored
use the viewerSettings GraphQL API instead of the 5y+-deprecated viewerConfiguration API (#63949)
This API is deprecated (see https://github.com/sourcegraph/sourcegraph/pull/63935). The browser extension is still using it, and we need this PR to remove its usage, and then we need to publish it. Then we can pick up https://github.com/sourcegraph/sourcegraph/pull/63935 again. ## Test plan Confirm that the browser extension uses the new GraphQL query (in the background page network devtools tab).
1 parent 175667d commit 2388317

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

client/browser/src/integration/github.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ describe('GitHub', () => {
5252
})
5353

5454
testContext.overrideGraphQL({
55-
ViewerConfiguration: () => ({
56-
viewerConfiguration: {
55+
ViewerSettings: () => ({
56+
viewerSettings: {
5757
subjects: [],
5858
merged: { contents: '', messages: [] },
5959
},
@@ -158,8 +158,8 @@ describe('GitHub', () => {
158158
// extensions: extensionSettings,
159159
// }
160160
// testContext.overrideGraphQL({
161-
// ViewerConfiguration: () => ({
162-
// viewerConfiguration: {
161+
// ViewerSettings: () => ({
162+
// viewerSettings: {
163163
// subjects: [
164164
// {
165165
// __typename: 'User',
@@ -321,8 +321,8 @@ describe('GitHub', () => {
321321
extensions: extensionSettings,
322322
}
323323
testContext.overrideGraphQL({
324-
ViewerConfiguration: () => ({
325-
viewerConfiguration: {
324+
ViewerSettings: () => ({
325+
viewerSettings: {
326326
subjects: [
327327
{
328328
__typename: 'User',
@@ -643,8 +643,8 @@ describe('GitHub', () => {
643643
extensions: extensionSettings,
644644
}
645645
testContext.overrideGraphQL({
646-
ViewerConfiguration: () => ({
647-
viewerConfiguration: {
646+
ViewerSettings: () => ({
647+
viewerSettings: {
648648
subjects: [
649649
{
650650
__typename: 'User',

client/browser/src/integration/gitlab.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('GitLab', () => {
4747
})
4848

4949
testContext.overrideGraphQL({
50-
ViewerConfiguration: () => ({
51-
viewerConfiguration: {
50+
ViewerSettings: () => ({
51+
viewerSettings: {
5252
subjects: [],
5353
merged: { contents: '', messages: [] },
5454
},
@@ -152,8 +152,8 @@ describe('GitLab', () => {
152152
extensions: extensionSettings,
153153
}
154154
testContext.overrideGraphQL({
155-
ViewerConfiguration: () => ({
156-
viewerConfiguration: {
155+
ViewerSettings: () => ({
156+
viewerSettings: {
157157
subjects: [
158158
{
159159
__typename: 'User',

client/browser/src/shared/platform/settings.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@sourcegraph/shared/src/settings/settings'
1515

1616
import { observeStorageKey, storage } from '../../browser-extension/web-extension-api/storage'
17-
import type { ViewerConfigurationResult } from '../../graphql-operations'
17+
import type { ViewerSettingsResult } from '../../graphql-operations'
1818
import { isInPage } from '../context'
1919

2020
const inPageClientSettingsKey = 'sourcegraphClientSettings'
@@ -35,7 +35,8 @@ function observeLocalStorageKey(key: string, defaultValue: string): Observable<s
3535
}
3636

3737
const createStorageSettingsCascade: () => Observable<SettingsCascade> = () => {
38-
/** Observable of the JSONC string of the settings.
38+
/**
39+
* Observable of the JSONC string of the settings.
3940
*
4041
* NOTE: We can't use LocalStorageSubject here because the JSONC string is stored raw in localStorage and LocalStorageSubject also does parsing.
4142
* This could be changed, but users already have settings stored, so it would need a migration for little benefit.
@@ -95,9 +96,8 @@ export function mergeCascades(
9596
}
9697
}
9798

98-
// This is a fragment on the DEPRECATED GraphQL API type ConfigurationCascade (not SettingsCascade) for backcompat.
99-
const configurationCascadeFragment = gql`
100-
fragment ConfigurationCascadeFields on ConfigurationCascade {
99+
const settingsCascadeFragment = gql`
100+
fragment SettingsCascadeFields on SettingsCascade {
101101
subjects {
102102
__typename
103103
...OrgSettingFields
@@ -167,42 +167,40 @@ const configurationCascadeFragment = gql`
167167

168168
/**
169169
* Fetches the settings cascade for the viewer.
170-
*
171-
* TODO(sqs): This uses the DEPRECATED GraphQL Query.viewerConfiguration and ConfigurationCascade for backcompat.
172170
*/
173171
export function fetchViewerSettings(requestGraphQL: PlatformContext['requestGraphQL']): Observable<{
174172
final: string
175173
subjects: SettingsSubject[]
176174
}> {
177175
return from(
178-
requestGraphQL<ViewerConfigurationResult>({
176+
requestGraphQL<ViewerSettingsResult>({
179177
request: gql`
180-
query ViewerConfiguration {
181-
viewerConfiguration {
182-
...ConfigurationCascadeFields
178+
query ViewerSettings {
179+
viewerSettings {
180+
...SettingsCascadeFields
183181
}
184182
}
185-
${configurationCascadeFragment}
183+
${settingsCascadeFragment}
186184
`,
187185
variables: {},
188186
mightContainPrivateInfo: false,
189187
})
190188
).pipe(
191189
map(dataOrThrowErrors),
192-
map(({ viewerConfiguration }) => {
193-
if (!viewerConfiguration) {
194-
throw new Error('fetchViewerSettings: empty viewerConfiguration')
190+
map(({ viewerSettings }) => {
191+
if (!viewerSettings) {
192+
throw new Error('fetchViewerSettings: empty viewerSettings')
195193
}
196194

197-
for (const subject of viewerConfiguration.subjects) {
195+
for (const subject of viewerSettings.subjects) {
198196
// User/org/global settings cannot be edited from the
199197
// browser extension (only client settings can).
200198
subject.viewerCanAdminister = false
201199
}
202200

203201
return {
204-
subjects: viewerConfiguration.subjects,
205-
final: viewerConfiguration.merged.contents,
202+
subjects: viewerSettings.subjects,
203+
final: viewerSettings.merged.contents,
206204
}
207205
})
208206
)

0 commit comments

Comments
 (0)