Skip to content

Commit

Permalink
Converted extensions query to a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
cohansen committed Jan 7, 2025
1 parent a2bed7f commit 916b15e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
2 changes: 0 additions & 2 deletions src/routes/plans/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ export const load: PageLoad = async ({ parent, params, url }) => {
initialPlan.model.view,
);
const initialPlanSnapshotId = getSearchParameterNumber(SearchParameters.SNAPSHOT_ID, url.searchParams);
const extensions = await effects.getExtensions(user);

return {
extensions,
initialActivityTypes,
initialPlan,
initialPlanSnapshotId,
Expand Down
5 changes: 5 additions & 0 deletions src/stores/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Extension } from '../types/extension';
import gql from '../utilities/gql';
import { gqlSubscribable } from './subscribable';

export const extensions = gqlSubscribable<Extension[]>(gql.SUB_EXTENSIONS, {}, [], null);
15 changes: 0 additions & 15 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3627,21 +3627,6 @@ const effects = {
}
},

async getExtensions(user: User | null): Promise<Extension[]> {
try {
const data = await reqHasura<Extension[]>(gql.GET_EXTENSIONS, {}, user);
const { extensions = [] } = data;
if (extensions != null) {
return extensions;
} else {
throw Error('Unable to retrieve extensions');
}
} catch (e) {
catchError(e as Error);
return [];
}
},

async getExternalEventTypes(plan_id: number, user: User | null): Promise<ExternalEventType[]> {
try {
const sourceData = await reqHasura<
Expand Down
32 changes: 16 additions & 16 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,22 +1460,6 @@ const gql = {
}
`,

GET_EXTENSIONS: `#graphql
query GetExtensions {
${Queries.EXTENSIONS} {
description
extension_roles {
extension_id
role
}
id
label
updated_at
url
}
}
`,

GET_EXTERNAL_EVENTS: `#graphql
query GetExternalEvents(
$sourceKey: String!,
Expand Down Expand Up @@ -2467,6 +2451,22 @@ const gql = {
}
`,

SUB_EXTENSIONS: `#graphql
subscription SubExtensions {
${Queries.EXTENSIONS} {
description
extension_roles {
extension_id
role
}
id
label
updated_at
url
}
}
`,

SUB_EXTERNAL_EVENT_TYPES: `#graphql
subscription SubExternalEventTypes {
models: ${Queries.EXTERNAL_EVENT_TYPES}(order_by: { name: asc }) {
Expand Down

0 comments on commit 916b15e

Please sign in to comment.