Skip to content

Commit

Permalink
Update Grafbase extension (#4932)
Browse files Browse the repository at this point in the history
* Handle errors in GraphQL response payload

* Run codegen

* Handle case where access token might not be able to access personal Account

* replace logo asset (#2)

* replace logo asset

* chore: remove service name from command title

* ray lint --fix

* Update changelog

---------

Co-authored-by: Jamie Barton <jamie@notrab.dev>
  • Loading branch information
mlafeldt and notrab authored Feb 27, 2023
1 parent 5cdd623 commit 58edc85
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
6 changes: 6 additions & 0 deletions extensions/grafbase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Grafbase Changelog

## 2023-02-27

- Use a better logo and shorter command name
- Handle scoped access tokens
- Improve error handling

## [Initial Version] - 2023-02-14

- Search projects
Expand Down
Binary file modified extensions/grafbase/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extensions/grafbase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"commands": [
{
"name": "search-projects",
"title": "Search Grafbase Projects",
"title": "Search Projects",
"description": "Explore your Grafbase projects, branches, deployments, and commit history.",
"mode": "view"
}
Expand Down
6 changes: 4 additions & 2 deletions extensions/grafbase/src/components/projects-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const GetProjectsByAccountSlugDocument = /* GraphQL */ `
`;

export default function ProjectsList() {
const { activeSlug, personalAccount } = useGrafbase();
const { activeSlug, personalAccount, organizationMemberships } = useGrafbase();

const { isLoading, data, revalidate } = useFetch<{ data: GetProjectsByAccountSlugQuery }>(apiUrl, {
method: "POST",
Expand All @@ -66,7 +66,9 @@ export default function ProjectsList() {
navigationTitle="Projects"
searchBarPlaceholder="Search Projects..."
isLoading={isLoading}
searchBarAccessory={personalAccount && <ScopeDropdown onChange={() => revalidate()} />}
searchBarAccessory={
(personalAccount || organizationMemberships) && <ScopeDropdown onChange={() => revalidate()} />
}
>
{!projects || projects?.length === 0 ? (
<List.EmptyView
Expand Down
21 changes: 18 additions & 3 deletions extensions/grafbase/src/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Scalars = {

export type AccessToken = {
__typename?: "AccessToken";
accountId?: Maybe<Scalars["ID"]>;
createdAt: Scalars["DateTime"];
id: Scalars["ID"];
name: Scalars["String"];
Expand All @@ -37,10 +38,11 @@ export type AccessTokenConnection = {
};

export type AccessTokenCreateInput = {
accountId?: InputMaybe<Scalars["ID"]>;
name: Scalars["String"];
};

export type AccessTokenCreatePayload = AccessTokenCreateSuccess | TokenLimitExceededError;
export type AccessTokenCreatePayload = AccessTokenCreateSuccess | InvalidAccountError | TokenLimitExceededError;

export type AccessTokenCreateSuccess = {
__typename?: "AccessTokenCreateSuccess";
Expand Down Expand Up @@ -170,6 +172,7 @@ export type DatabaseUsage = {
dbReads: Distribution;
dbSize: Distribution;
dbWrites: Distribution;
granularity: DatabaseUsageGranularity;
requestCount: Distribution;
};

Expand All @@ -179,6 +182,13 @@ export type DatabaseUsageFilter = {
startDate?: InputMaybe<Scalars["DateTime"]>;
};

export enum DatabaseUsageGranularity {
Daily = "DAILY",
Hourly = "HOURLY",
Monthly = "MONTHLY",
Weekly = "WEEKLY",
}

/** Deployment */
export type Deployment = {
__typename?: "Deployment";
Expand Down Expand Up @@ -409,6 +419,11 @@ export type GitRepository = {
url: Scalars["String"];
};

export type InvalidAccountError = {
__typename?: "InvalidAccountError";
query: Query;
};

export type InvalidDatabaseRegionsError = {
__typename?: "InvalidDatabaseRegionsError";
invalid: Array<Scalars["String"]>;
Expand Down Expand Up @@ -1422,7 +1437,7 @@ export type User = {
name: Scalars["String"];
organizationMemberships: Array<Member>;
organizations: OrganizationConnection;
personalAccount: PersonalAccount;
personalAccount?: Maybe<PersonalAccount>;
};

export type UserOrganizationsArgs = {
Expand Down Expand Up @@ -1564,7 +1579,7 @@ export type GetScopesQuery = {
id: string;
name: string;
avatarUrl?: string | null;
personalAccount: { __typename?: "PersonalAccount"; id: string; name: string; slug: string };
personalAccount?: { __typename?: "PersonalAccount"; id: string; name: string; slug: string } | null;
organizationMemberships: Array<{
__typename?: "Member";
account:
Expand Down
17 changes: 12 additions & 5 deletions extensions/grafbase/src/hooks/use-grafbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useGrafbase = () => {
// TODO memo

// TODO create a single client
useFetch<{ data: GetScopesQuery }>(apiUrl, {
useFetch<{ data: GetScopesQuery; errors: any }>(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -76,16 +76,23 @@ export const useGrafbase = () => {
query: GetScopesDocument,
}),
onError(error) {
console.error(error);
showToast({
title: "Oops",
message: error?.message ?? "Something went wrong. Try again later.",
style: Toast.Style.Failure,
});
},
async onData(data) {
const {
data: { viewer },
} = data;
async onData({ data: { viewer }, errors }) {
if (errors) {
console.error(errors);
showToast({
title: "Oops",
message: errors[0]?.message ?? "Something went wrong. Try again later.",
style: Toast.Style.Failure,
});
return;
}

setAvatarUrl(viewer?.avatarUrl);
setPersonalAccount(viewer?.personalAccount);
Expand Down

0 comments on commit 58edc85

Please sign in to comment.