diff --git a/packages/app/package.json b/packages/app/package.json index 98083c41d8e..df850925ddf 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -268,11 +268,11 @@ "@babel/preset-typescript": "^7.3.3", "@babel/register": "^7.13.16", "@divyenduz/ts-graphql-plugin": "^0.1.0", - "@graphql-codegen/cli": "^1.21.8", - "@graphql-codegen/fragment-matcher": "^1.17.8", - "@graphql-codegen/typescript": "^1.21.8", - "@graphql-codegen/typescript-graphql-files-modules": "^1.18.1", - "@graphql-codegen/typescript-operations": "^1.17.8", + "@graphql-codegen/cli": "^2.3.1", + "@graphql-codegen/fragment-matcher": "^2.0.0", + "@graphql-codegen/typescript": "^2.0.0", + "@graphql-codegen/typescript-graphql-files-modules": "^2.0.0", + "@graphql-codegen/typescript-operations": "^2.0.0", "@sentry/cli": "^1.47.1", "@types/codemirror": "^0.0.72", "@types/debug": "^4.1.1", diff --git a/packages/app/src/app/graphql/introspection-result.ts b/packages/app/src/app/graphql/introspection-result.ts index f8a7eb527d8..50c549fca12 100644 --- a/packages/app/src/app/graphql/introspection-result.ts +++ b/packages/app/src/app/graphql/introspection-result.ts @@ -1,111 +1,32 @@ -export interface IntrospectionResultData { - __schema: { - types: { - kind: string; - name: string; - possibleTypes: { - name: string; - }[]; - }[]; +export interface PossibleTypesResultData { + possibleTypes: { + [key: string]: string[]; }; } -const result: IntrospectionResultData = { - __schema: { - types: [ - { - kind: 'UNION', - name: 'BookmarkEntity', - possibleTypes: [ - { - name: 'Team', - }, - { - name: 'User', - }, - ], - }, - { - kind: 'UNION', - name: 'Repository', - possibleTypes: [ - { - name: 'GitHubRepository', - }, - ], - }, - { - kind: 'UNION', - name: 'ReferenceMetadata', - possibleTypes: [ - { - name: 'CodeReferenceMetadata', - }, - { - name: 'ImageReferenceMetadata', - }, - { - name: 'PreviewReferenceMetadata', - }, - { - name: 'UserReferenceMetadata', - }, - ], - }, - { - kind: 'UNION', - name: 'BranchEvent', - possibleTypes: [ - { - name: 'PullRequestCommentEvent', - }, - { - name: 'PullRequestEvent', - }, - { - name: 'PullRequestReviewCommentEvent', - }, - { - name: 'PullRequestReviewEvent', - }, - ], - }, - { - kind: 'UNION', - name: 'RepositoryEvent', - possibleTypes: [ - { - name: 'InstallationEvent', - }, - ], - }, - { - kind: 'UNION', - name: 'ProjectEvent', - possibleTypes: [ - { - name: 'PullRequestCommentEvent', - }, - { - name: 'PullRequestEvent', - }, - { - name: 'PullRequestReviewCommentEvent', - }, - { - name: 'PullRequestReviewEvent', - }, - ], - }, - { - kind: 'UNION', - name: 'TeamEvent', - possibleTypes: [ - { - name: 'TeamSubscriptionEvent', - }, - ], - }, +const result: PossibleTypesResultData = { + possibleTypes: { + BookmarkEntity: ['Team', 'User'], + Repository: ['GitHubRepository'], + ReferenceMetadata: [ + 'CodeReferenceMetadata', + 'ImageReferenceMetadata', + 'PreviewReferenceMetadata', + 'UserReferenceMetadata', ], + BranchEvent: [ + 'PullRequestCommentEvent', + 'PullRequestEvent', + 'PullRequestReviewCommentEvent', + 'PullRequestReviewEvent', + ], + RepositoryEvent: ['InstallationEvent'], + ProjectEvent: [ + 'PullRequestCommentEvent', + 'PullRequestEvent', + 'PullRequestReviewCommentEvent', + 'PullRequestReviewEvent', + ], + TeamEvent: ['TeamSubscriptionEvent'], }, }; export default result; diff --git a/packages/app/src/app/graphql/types.ts b/packages/app/src/app/graphql/types.ts index 201d6cef7ff..9331409e9f4 100644 --- a/packages/app/src/app/graphql/types.ts +++ b/packages/app/src/app/graphql/types.ts @@ -1,5 +1,12 @@ export type Maybe = T | null; -export type Exact = { [K in keyof T]: T[K] }; +export type InputMaybe = Maybe; +export type Exact = { + [K in keyof T]: T[K]; +}; +export type MakeOptional = Omit & + { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & + { [SubKey in K]: Maybe }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: string; @@ -7,170 +14,312 @@ export type Scalars = { Boolean: boolean; Int: number; Float: number; + UUID4: any; + DateTime: any; + NaiveDateTime: any; + Base64: any; +}; + +export type RootQueryType = { + __typename?: 'RootQueryType'; + album: Maybe; + albums: Array; /** - * The `UUID` scalar type represents UUID4 compliant string data, represented as UTF-8 - * character sequences. The UUID4 type is most often used to represent unique - * human-readable ID strings. + * Get a single branch by its short ID. + * + * Returns a "not found" error if the branch does not exist or is inaccessible by the current user. + * Anonymous users may use this endpoint for branches that exist on read-only projects (see + * `mutation importReadOnlyProject`). + * + * Branches represent real or potential git branches on a particular team's project. Branch short + * IDs are short alphanumeric strings that point to a particular repository + team + branch name. + * Remember that a user may have access to the same branch on multiple teams' projects. + * + * To look up a branch by repository + team + branch name, see `query branchByName`. + * + * Example (for branch with short ID `abc123`): + * + * ```gql + * query branchById(id: "abc123") { + * name + * } + * ``` */ - UUID4: any; + branchById: Branch; /** - * The `DateTime` scalar type represents a date and time in the UTC - * timezone. The DateTime appears in a JSON response as an ISO8601 formatted - * string, including UTC timezone ("Z"). The parsed date and time string will - * be converted to UTC if there is an offset. + * Get a single branch by its repository, team, and name. + * + * Returns a "not found" error if the branch does not exist or is inaccessible by the current user. + * Anonymous users may use this endpoint for branches that exist on read-only projects (see + * `mutation importReadOnlyProject`). + * + * Branches represent real or potential git branches on a particular team's project. Remember that + * a user may have access to the same branch on multiple teams' projects. + * + * To look up a branch by its short ID, see `query branchById`. + * + * Example (for `codesandbox/test-repo` branch `test-branch`): + * + * ```gql + * query branchByName( + * provider: GITHUB, + * owner: "codesandbox", + * name: "test-repo", + * branch: "test-branch", + * team: "987b6fcd-2a3b-41fe-b1e6-ac33565824b9" + * ) + * ``` */ - DateTime: any; + branchByName: Branch; + curatedAlbums: Array; + /** Get git repo and related V1 sandboxes */ + git: Maybe; /** - * The `Naive DateTime` scalar type represents a naive date and time without - * timezone. The DateTime appears in a JSON response as an ISO8601 formatted - * string. + * Get repositories owned by a GitHub organization. + * + * If either `page` or `perPage` are specified, then a single page of results will be returned. + * If neither argument is given, then all results will be returned. Note that this still requires + * paginated requests to the GitHub API, but the server will concatenate the results. */ - NaiveDateTime: any; - /** Base64 encoded file contents. */ - Base64: any; + githubOrganizationRepos: Maybe>; + /** Get a repository as it appears on GitHub */ + githubRepo: Maybe; + /** The various limits in place for free and paying users and teams */ + limits: Limits; + /** Get current user */ + me: Maybe; + /** + * Get a single project by its repository and team. + * + * Projects are identified by repository-team pairs. For public repositories, there may also be a + * single project that does not have an associated team. For a list of all projects for a given + * repository, see `query projectsByRepository`. + * + * Example (for `https://github.com/codesandbox/test-repo.git`): + * + * ```gql + * query project( + * git_provider: GITHUB, + * owner: "codesandbox", + * repo: "test-repo", + * team: "57ca3ef5-475b-47bf-9530-a686c527e174" + * ) { id } + * ``` + */ + project: Maybe; + /** + * Get all projects for the given repository accessible by the current user. Returns an empty list + * if no such projects are available, or no version of this project has been imported yet. + * + * Projects are identified by repository-team pairs. For public repositories, there may also be a + * single project that does not have an associated team. This query returns all of the projects + * accessible by the current user (as many as `[# of user teams] + 1`). For information about + * a project associated with a specific team, see `query project`. + * + * Example (for `https://github.com/codesandbox/test-repo.git`): + * + * ```gql + * query projects( + * provider: GITHUB, + * owner: "codesandbox", + * name: "test-repo" + * ) { id } + * ``` + */ + projects: Array; + /** + * Get a list of teams that have interacted with a repository recently + * + * This endpoint is intended to be used when a user has access to a repository, but does not + * belong to any teams where the repository has been imported. It returns a brief list of teams + * (10) that have interacted with that repository recently, with the intention that the user may + * wish to request an invitation to one of those teams. + * + * **Note**: The teams returned by this endpoint are likely to be relevant for **private** + * repositories only, and unlikely to be relevant for public repositories. + * + * ```gql + * query recentTeamsByRepository( + * provider: GITHUB, + * owner: "codesandbox", + * name: "test-repo" + * ) { id } + * ``` + */ + recentTeamsByRepository: Array; + /** Get a sandbox */ + sandbox: Maybe; + /** A team from an invite token */ + teamByToken: Maybe; }; -export type Album = { - __typename?: 'Album'; - id: Scalars['ID']; - sandboxes: Array; - title: Maybe; +export type RootQueryTypeAlbumArgs = { + albumId: Scalars['ID']; }; -export enum Authorization { - Comment = 'COMMENT', - None = 'NONE', - Owner = 'OWNER', - Read = 'READ', - WriteCode = 'WRITE_CODE', - WriteProject = 'WRITE_PROJECT', -} +export type RootQueryTypeAlbumsArgs = { + username: Scalars['String']; +}; -export enum AuthType { - Basic = 'BASIC', - Bearer = 'BEARER', -} +export type RootQueryTypeBranchByIdArgs = { + id: Scalars['String']; +}; -export type BillingDetails = { - __typename?: 'BillingDetails'; - amount: Scalars['Int']; - currency: Scalars['String']; - date: Scalars['String']; +export type RootQueryTypeBranchByNameArgs = { + branch: Scalars['String']; + name: Scalars['String']; + owner: Scalars['String']; + provider: GitProvider; + team: InputMaybe; }; -export type BillingPreview = { - __typename?: 'BillingPreview'; - immediatePayment: Maybe; - nextPayment: Maybe; +export type RootQueryTypeGitArgs = { + branch: Scalars['String']; + path: Scalars['String']; + repo: Scalars['String']; + username: Scalars['String']; }; -export type Bookmarked = { - __typename?: 'Bookmarked'; - entity: Maybe; - isBookmarked: Maybe; +export type RootQueryTypeGithubOrganizationReposArgs = { + organization: Scalars['String']; + page: InputMaybe; + perPage: InputMaybe; }; -/** A team or the current user */ -export type BookmarkEntity = Team | User; +export type RootQueryTypeGithubRepoArgs = { + owner: Scalars['String']; + repo: Scalars['String']; +}; -/** - * Branch of a Repository imported to CodeSandbox. - * - * Branches often represent git branches available from the git provider, but they can also - * represent the contributions of read-only users that have not yet forked and committed their work. - * Branches on CodeSandbox do not persist to the git provider until a commit is made, and branches - * on the git provider don't appear in CodeSandbox unless imported by an automated process (like the - * GitHub App webhooks) or manually by a user. - */ -export type Branch = { - __typename?: 'Branch'; - /** - * Whether or not AI features should be enabled for this branch. - * This is the final calculated value based on the team subscription status, team settings, and project settings. - */ - aiConsent: Scalars['Boolean']; - /** Active users connected to this branch */ - connections: Array; - /** Whether this branch is a contribution branch made by a read-only user */ - contribution: Scalars['Boolean']; - /** - * Whether the current user is the owner of this contribution branch. Can be - * used to override project-level `READ` authorization. Always returns `false` if the - * current branch is not a contribution branch. - */ - contributionOwner: Scalars['Boolean']; - /** Alphanumeric short ID of the branch, for use with Pitcher */ - id: Scalars['String']; - /** Timestamp of the last time the current user accessed this branch on CodeSandbox */ - lastAccessedAt: Maybe; - /** Information about the last commit made by CodeSandbox on this branch */ - lastCommit: Maybe; - /** Branch name as it appears in git */ +export type RootQueryTypeProjectArgs = { + gitProvider: InputMaybe; + owner: Scalars['String']; + repo: Scalars['String']; + team: InputMaybe; +}; + +export type RootQueryTypeProjectsArgs = { name: Scalars['String']; - /** Branch owner, in the case of a contribution branch by a read-only user */ - owner: Maybe; - /** Parent project of this branch */ - project: Project; - /** Open pull requests from this head branch */ - pullRequests: Array; - settings: BranchSettings; - /** The name of the branch the current branch was created from. Only available if this branch was created via CodeSandbox. */ - sourceBranch: Maybe; - /** Information about the underlying git status of this branch */ - status: Maybe; - /** Whether or not this branch exists on GitHub. Deduced from local information, so not guaranteed 100% accurate */ - upstream: Scalars['Boolean']; + owner: Scalars['String']; + provider: GitProvider; }; -/** Subscription update about active users connected to a branch */ -export type BranchConnections = { - __typename?: 'BranchConnections'; - branchId: Scalars['String']; - connections: Array; +export type RootQueryTypeRecentTeamsByRepositoryArgs = { + name: Scalars['String']; + owner: Scalars['String']; + provider: GitProvider; }; -/** Events related to a specific branch. */ -export type BranchEvent = - | PullRequestCommentEvent - | PullRequestEvent - | PullRequestReviewCommentEvent - | PullRequestReviewEvent; +export type RootQueryTypeSandboxArgs = { + sandboxId: Scalars['ID']; +}; -/** Subscription update about a commit made by CodeSandbox for a branch */ -export type BranchLastCommit = { - __typename?: 'BranchLastCommit'; - branchId: Scalars['String']; - lastCommit: LastCommit; +export type RootQueryTypeTeamByTokenArgs = { + inviteToken: Scalars['String']; }; -/** Settings for this branch. Stored with the branch so does not incur an extra db query */ -export type BranchSettings = { - __typename?: 'BranchSettings'; - protected: Scalars['Boolean']; +export type Album = { + __typename?: 'Album'; + id: Scalars['ID']; + sandboxes: Array; + title: Maybe; }; -/** Subscription update about the underlying git status of a branch */ -export type BranchStatus = { - __typename?: 'BranchStatus'; - branchId: Scalars['String']; - status: Status; +/** A Sandbox */ +export type Sandbox = { + __typename?: 'Sandbox'; + alias: Maybe; + alwaysOn: Maybe; + author: Maybe; + authorId: Maybe; + authorization: Authorization; + /** If the sandbox has created a PR, this will refer to the git that you will merge into */ + baseGit: Maybe; + collaborators: Array; + collection: Maybe; + comment: Maybe; + comments: Array; + /** If the sandbox is a template this will be set */ + customTemplate: Maybe