Skip to content

Commit

Permalink
[SG-28893] refactor: extract graphql folder into a new http-client pa…
Browse files Browse the repository at this point in the history
…ckage. (sourcegraph#29346)

Co-authored-by: gitstart-sourcegraph <gitstart@users.noreply.github.com>
  • Loading branch information
gitstart-sourcegraph and gitstart authored Jan 13, 2022
1 parent 369464f commit e7e705c
Show file tree
Hide file tree
Showing 349 changed files with 489 additions and 421 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lsif-ts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- client/web
- client/wildcard
- client/common
- client/http-client
- client/codeintellify
- client/template-parser
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ package-lock.json
.nyc_output/
coverage/
out/
client/shared/src/graphql/schema.ts
client/shared/src/schema.ts
client/web/src/schema/*
puppeteer/
package-lock.json
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"./client/browser",
"./client/build-config",
"./client/shared",
"./client/http-client",
"./client/branded",
"./client/wildcard",
"./client/storybook",
Expand Down
2 changes: 1 addition & 1 deletion client/branded/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
out/
src/graphql/schema.ts
src/schema.ts
src/graphql-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
import addDomainPermissionToggle from 'webext-domain-permission-toggle'

import { isDefined } from '@sourcegraph/common'
import { GraphQLResult, requestGraphQLCommon } from '@sourcegraph/http-client'
import { createExtensionHostWorker } from '@sourcegraph/shared/src/api/extension/worker'
import { GraphQLResult, requestGraphQLCommon } from '@sourcegraph/shared/src/graphql/graphql'
import { EndpointPair } from '@sourcegraph/shared/src/platform/context'
import { fetchCache } from '@sourcegraph/shared/src/util/fetchCache'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { catchError, map, mapTo } from 'rxjs/operators'
import { Optional } from 'utility-types'

import { asError } from '@sourcegraph/common'
import { GraphQLResult } from '@sourcegraph/http-client'
import { AnchorLink, setLinkComponent } from '@sourcegraph/shared/src/components/Link'
import { GraphQLResult } from '@sourcegraph/shared/src/graphql/graphql'
import { isFirefox } from '@sourcegraph/shared/src/util/browserDetection'
import { useObservable } from '@sourcegraph/shared/src/util/useObservable'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLResult } from '@sourcegraph/shared/src/graphql/graphql'
import { GraphQLResult } from '@sourcegraph/http-client'
import { fetchCache } from '@sourcegraph/shared/src/util/fetchCache'

import { OptionFlagValues } from '../../shared/util/optionFlags'
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/backend/diffs.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

import { dataOrThrowErrors, gql } from '@sourcegraph/http-client'
import { RepoNotFoundError } from '@sourcegraph/shared/src/backend/errors'
import { dataOrThrowErrors, gql } from '@sourcegraph/shared/src/graphql/graphql'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import { memoizeObservable } from '@sourcegraph/shared/src/util/memoizeObservable'

Expand Down
7 changes: 1 addition & 6 deletions client/browser/src/shared/backend/requestGraphQl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { once } from 'lodash'
import { from, Observable } from 'rxjs'
import { switchMap, take } from 'rxjs/operators'

import {
GraphQLResult,
getGraphQLClient,
GraphQLClient,
requestGraphQLCommon,
} from '@sourcegraph/shared/src/graphql/graphql'
import { GraphQLResult, getGraphQLClient, GraphQLClient, requestGraphQLCommon } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'

import { background } from '../../browser-extension/web-extension-api/runtime'
Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/backend/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

import { dataOrThrowErrors, gql } from '@sourcegraph/shared/src/graphql/graphql'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { dataOrThrowErrors, gql } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'

export const fetchSite = (requestGraphQL: PlatformContext['requestGraphQL']): Observable<GQL.ISite> =>
requestGraphQL<GQL.IQuery>({
Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/backend/userEvents.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql } from '@sourcegraph/shared/src/graphql/graphql'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { gql } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'

import { UserEvent, EventSource } from '../../graphql-operations'
import { isDefaultSourcegraphUrl } from '../util/context'
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/code-hosts/bitbucket/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fromFetch } from 'rxjs/fetch'
import { filter, map } from 'rxjs/operators'

import { isDefined } from '@sourcegraph/common'
import { checkOk } from '@sourcegraph/shared/src/backend/fetch'
import { checkOk } from '@sourcegraph/http-client'
import { memoizeObservable } from '@sourcegraph/shared/src/util/memoizeObservable'

import { DiffResolvedRevisionSpec } from '../../repo'
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/code-hosts/gitlab/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Observable, zip, of } from 'rxjs'
import { fromFetch } from 'rxjs/fetch'
import { map, switchMap } from 'rxjs/operators'

import { checkOk } from '@sourcegraph/shared/src/backend/fetch'
import { checkOk } from '@sourcegraph/http-client'
import { memoizeObservable } from '@sourcegraph/shared/src/util/memoizeObservable'

import { GitLabInfo } from './scrape'
Expand Down
5 changes: 2 additions & 3 deletions client/browser/src/shared/code-hosts/phabricator/backend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { from, Observable, of, throwError } from 'rxjs'
import { fromFetch } from 'rxjs/fetch'
import { map, mapTo, switchMap, catchError } from 'rxjs/operators'

import { dataOrThrowErrors, gql, checkOk } from '@sourcegraph/http-client'
import { isRepoNotFoundErrorLike } from '@sourcegraph/shared/src/backend/errors'
import { checkOk } from '@sourcegraph/shared/src/backend/fetch'
import { dataOrThrowErrors, gql } from '@sourcegraph/shared/src/graphql/graphql'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'
import { memoizeObservable } from '@sourcegraph/shared/src/util/memoizeObservable'
import { RepoSpec, FileSpec, ResolvedRevisionSpec } from '@sourcegraph/shared/src/util/url'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFile } from 'mz/fs'
import { Observable, throwError, of } from 'rxjs'

import { SuccessGraphQLResult } from '@sourcegraph/shared/src/graphql/graphql'
import { IMutation, IQuery } from '@sourcegraph/shared/src/graphql/schema'
import { SuccessGraphQLResult } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import { IMutation, IQuery } from '@sourcegraph/shared/src/schema'
import { resetAllMemoizationCaches } from '@sourcegraph/shared/src/util/memoizeObservable'

import { DiffOrBlobInfo } from '../shared/codeHost'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react'
import { noop } from 'lodash'
import * as React from 'react'

import { HTTPStatusError } from '@sourcegraph/shared/src/backend/fetch'
import { HTTPStatusError } from '@sourcegraph/http-client'

import { ViewOnSourcegraphButton } from './ViewOnSourcegraphButton'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { snakeCase } from 'lodash'
import React, { useEffect } from 'react'

import { ErrorLike, isErrorLike } from '@sourcegraph/common'
import { isHTTPAuthError } from '@sourcegraph/shared/src/backend/fetch'
import { isHTTPAuthError } from '@sourcegraph/http-client'

import { SourcegraphIconButton, SourcegraphIconButtonProps } from '../../components/SourcegraphIconButton'
import { getPlatformName, isDefaultSourcegraphUrl } from '../../util/context'
Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/code-hosts/shared/codeHost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import * as sourcegraph from 'sourcegraph'
import { DiffPart } from '@sourcegraph/codeintellify'
import { Range } from '@sourcegraph/extension-api-classes'
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
import { SuccessGraphQLResult } from '@sourcegraph/http-client'
import { wrapRemoteObservable } from '@sourcegraph/shared/src/api/client/api/common'
import { FlatExtensionHostAPI } from '@sourcegraph/shared/src/api/contract'
import { ExtensionCodeEditor } from '@sourcegraph/shared/src/api/extension/api/codeEditor'
import { NotificationType } from '@sourcegraph/shared/src/api/extension/extensionHostApi'
import { integrationTestContext } from '@sourcegraph/shared/src/api/integration-test/testHelpers'
import { Controller } from '@sourcegraph/shared/src/extensions/controller'
import { SuccessGraphQLResult } from '@sourcegraph/shared/src/graphql/graphql'
import { IQuery } from '@sourcegraph/shared/src/graphql/schema'
import { IQuery } from '@sourcegraph/shared/src/schema'
import { NOOP_TELEMETRY_SERVICE } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { resetAllMemoizationCaches } from '@sourcegraph/shared/src/util/memoizeObservable'
import { MockIntersectionObserver } from '@sourcegraph/shared/src/util/MockIntersectionObserver'
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/code-hosts/shared/codeHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ import {
} from '@sourcegraph/codeintellify'
import { asError, isDefined } from '@sourcegraph/common'
import { TextDocumentDecoration, WorkspaceRoot } from '@sourcegraph/extension-api-types'
import { isHTTPAuthError } from '@sourcegraph/http-client'
import { ActionItemAction, urlForClientCommandOpen } from '@sourcegraph/shared/src/actions/ActionItem'
import { wrapRemoteObservable } from '@sourcegraph/shared/src/api/client/api/common'
import { HoverMerged } from '@sourcegraph/shared/src/api/client/types/hover'
import { DecorationMapByLine } from '@sourcegraph/shared/src/api/extension/api/decorations'
import { CodeEditorData, CodeEditorWithPartialModel } from '@sourcegraph/shared/src/api/viewerTypes'
import { isRepoNotFoundErrorLike } from '@sourcegraph/shared/src/backend/errors'
import { isHTTPAuthError } from '@sourcegraph/shared/src/backend/fetch'
import {
CommandListClassProps,
CommandListPopoverButtonClassProps,
Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/code-hosts/shared/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Observable, of, throwError } from 'rxjs'

import { GraphQLResult, SuccessGraphQLResult } from '@sourcegraph/shared/src/graphql/graphql'
import { IQuery } from '@sourcegraph/shared/src/graphql/schema'
import { GraphQLResult, SuccessGraphQLResult } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import { IQuery } from '@sourcegraph/shared/src/schema'

export interface GraphQLResponseMap {
[requestName: string]: (
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/components/CodeViewToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as H from 'history'
import * as React from 'react'

import { ErrorLike, isErrorLike } from '@sourcegraph/common'
import { isHTTPAuthError } from '@sourcegraph/http-client'
import { ActionNavItemsClassProps, ActionsNavItems } from '@sourcegraph/shared/src/actions/ActionsNavItems'
import { ContributionScope } from '@sourcegraph/shared/src/api/extension/api/context/context'
import { ContributableMenu } from '@sourcegraph/shared/src/api/protocol'
import { isHTTPAuthError } from '@sourcegraph/shared/src/backend/fetch'
import { ExtensionsControllerProps } from '@sourcegraph/shared/src/extensions/controller'
import { PlatformContextProps } from '@sourcegraph/shared/src/platform/context'
import { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/platform/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { combineLatest, ReplaySubject } from 'rxjs'
import { map } from 'rxjs/operators'

import { asError } from '@sourcegraph/common'
import { isHTTPAuthError } from '@sourcegraph/shared/src/backend/fetch'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { isHTTPAuthError } from '@sourcegraph/http-client'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'
import { mutateSettings, updateSettings } from '@sourcegraph/shared/src/settings/edit'
import { EMPTY_SETTINGS_CASCADE, gqlToCascade } from '@sourcegraph/shared/src/settings/settings'
import { LocalStorageSubject } from '@sourcegraph/shared/src/util/LocalStorageSubject'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Subscribable, from } from 'rxjs'

import { checkOk } from '@sourcegraph/http-client'
import { ExecutableExtension } from '@sourcegraph/shared/src/api/extension/activation'
import { checkOk } from '@sourcegraph/shared/src/backend/fetch'
import { ExtensionManifest } from '@sourcegraph/shared/src/extensions/extensionManifest'
import { isFirefox } from '@sourcegraph/shared/src/util/browserDetection'

Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/platform/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { from, fromEvent, Observable } from 'rxjs'
import { distinctUntilChanged, filter, map, startWith } from 'rxjs/operators'

import { isErrorLike } from '@sourcegraph/common'
import { dataOrThrowErrors, gql } from '@sourcegraph/http-client'
import { SettingsEdit } from '@sourcegraph/shared/src/api/client/services/settings'
import { dataOrThrowErrors, gql } from '@sourcegraph/shared/src/graphql/graphql'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'
import {
mergeSettings,
SettingsCascade,
Expand Down
2 changes: 1 addition & 1 deletion client/browser/src/shared/platform/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkOk } from '@sourcegraph/shared/src/backend/fetch'
import { checkOk } from '@sourcegraph/http-client'

import { isDefaultSourcegraphUrl } from '../util/context'

Expand Down
4 changes: 2 additions & 2 deletions client/browser/src/shared/repo/backend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { from, Observable } from 'rxjs'
import { delay, filter, map, retryWhen, switchMap } from 'rxjs/operators'

import { createAggregateError } from '@sourcegraph/common'
import { dataOrThrowErrors, gql } from '@sourcegraph/http-client'
import {
CloneInProgressError,
RepoNotFoundError,
RevisionNotFoundError,
isCloneInProgressErrorLike,
} from '@sourcegraph/shared/src/backend/errors'
import { dataOrThrowErrors, gql } from '@sourcegraph/shared/src/graphql/graphql'
import * as GQL from '@sourcegraph/shared/src/graphql/schema'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
import * as GQL from '@sourcegraph/shared/src/schema'
import { sha256 } from '@sourcegraph/shared/src/util/hashCode'
import { memoizeObservable } from '@sourcegraph/shared/src/util/memoizeObservable'
import {
Expand Down
1 change: 1 addition & 0 deletions client/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ "path": "../shared" },
{ "path": "../branded" },
{ "path": "../../schema" },
{ "path": "../http-client" },
{ "path": "../common" },
{ "path": "../codeintellify" },
],
Expand Down
1 change: 1 addition & 0 deletions client/http-client/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
13 changes: 13 additions & 0 deletions client/http-client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check

const baseConfig = require('../../.eslintrc.js')

module.exports = {
extends: '../../.eslintrc.js',
parserOptions: {
...baseConfig.parserOptions,
project: [__dirname + '/tsconfig.json'],
},
rules: {},
overrides: baseConfig.overrides,
}
3 changes: 3 additions & 0 deletions client/http-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Http Client

Generic logic for sending and handling HTTP requests from our client applications.
5 changes: 5 additions & 0 deletions client/http-client/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @ts-check

module.exports = {
extends: '../../babel.config.js',
}
13 changes: 13 additions & 0 deletions client/http-client/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check

const config = require('../../jest.config.base')

const exportedConfig = {
...config,
displayName: 'http-client',
rootDir: __dirname,
roots: ['<rootDir>'],
verbose: true,
}

module.exports = exportedConfig
13 changes: 13 additions & 0 deletions client/http-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "@sourcegraph/http-client",
"version": "0.0.1",
"description": "Sourcegraph http-client",
"main": "./src/index.ts",
"sideEffects": false,
"license": "Apache-2.0",
"scripts": {
"eslint": "eslint --cache 'src/**/*.[jt]s?(x)'",
"test": "jest"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InMemoryCache } from '@apollo/client'

import { TypedTypePolicies } from '../../graphql-operations'
import { IExtensionRegistry } from '../schema'
import { TypedTypePolicies } from '@sourcegraph/shared/src/graphql-operations'
import { IExtensionRegistry } from '@sourcegraph/shared/src/schema'

// Defines how the Apollo cache interacts with our GraphQL schema.
// See https://www.apollographql.com/docs/react/caching/cache-configuration/#typepolicy-fields
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './fromObservableQuery'
export * from './client'
export * from './hooks'
export * from './persistenceMapper'
export * from './cache'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IQuery } from '../schema'
import { IQuery } from '@sourcegraph/shared/src/schema'

/**
* Hardcoded names of the queries which will be persisted to the local storage.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Omit } from 'utility-types'

import { createAggregateError } from '@sourcegraph/common'

import { checkOk } from '../backend/fetch'
import { checkOk } from '../http-status-error'

import { GRAPHQL_URI } from './constants'

Expand Down
1 change: 1 addition & 0 deletions client/http-client/src/graphql/links/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './concurrent-requests-link'
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions client/http-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './graphql/types'
export * from './graphql/graphql'
export * from './graphql/constants'
export * from './graphql/links/concurrent-requests-link'
export * from './http-status-error'
12 changes: 12 additions & 0 deletions client/http-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"sourceRoot": "src",
"rootDir": ".",
"outDir": "./out",
"baseUrl": "./src",
},
"include": ["./src/**/*", "./*.ts"],
"references": [{ "path": "../common" }],
}
2 changes: 1 addition & 1 deletion client/shared/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
out/
src/graphql/schema.ts
src/schema.ts
src/graphql-operations.ts
Loading

0 comments on commit e7e705c

Please sign in to comment.