Skip to content

Commit

Permalink
Comment resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
MayankJha014 committed Feb 24, 2025
1 parent 1284926 commit 5a86586
Show file tree
Hide file tree
Showing 2 changed files with 6,382 additions and 291 deletions.
182 changes: 91 additions & 91 deletions src/graphql/types/Query/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,105 +5,105 @@ import { PluginRef } from "../Plugins/Plugins";
import pluginsData from "../Plugins/pluginData.json" assert { type: "json" };

builder.queryField("plugins", (t) =>
t.field({
type: [PluginRef],
args: {
after: t.arg.string(),
before: t.arg.string(),
first: t.arg.int(),
last: t.arg.int(),
},
description: "Fetch all available plugins",
resolve: async (_parent, _args, ctx) => {
try {
// Check authentication
if (!ctx.currentClient.isAuthenticated) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}
t.field({
type: [PluginRef],
args: {
after: t.arg.string(),
before: t.arg.string(),
first: t.arg.int(),
last: t.arg.int(),
},
description: "Fetch all available plugins",
resolve: async (_parent, _args, ctx) => {
try {
// Check authentication
if (!ctx.currentClient.isAuthenticated) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}

return pluginsData;
} catch (error) {
if (error instanceof TalawaGraphQLError) {
throw error;
}
throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}
},
}),
return pluginsData;
} catch (error) {
if (error instanceof TalawaGraphQLError) {
throw error;
}
throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}
},
})
);

const pluginCache = new Map(
pluginsData.map((plugin) => [plugin.pluginName.toLowerCase(), plugin]),
pluginsData.map((plugin) => [plugin.pluginName.toLowerCase(), plugin])
);

builder.queryField("plugin", (t) =>
t.field({
type: PluginRef,
args: {
input: t.arg({
type: QueryPluginInput,
required: true,
}),
},
resolve: async (_parent, { input }, ctx) => {
try {
// Check authentication
if (!ctx.currentClient.isAuthenticated) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}
// Validate input
if (!input.pluginName?.trim()) {
throw new TalawaGraphQLError({
extensions: {
code: "invalid_arguments",
issues: [
{
argumentPath: ["input", "pluginName"],
message: "Plugin name cannot be empty",
},
],
},
});
}
t.field({
type: PluginRef,
args: {
input: t.arg({
type: QueryPluginInput,
required: true,
}),
},
resolve: async (_parent, { input }, ctx) => {
try {
// Check authentication
if (!ctx.currentClient.isAuthenticated) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}
// Validate input
if (!input.pluginName?.trim()) {
throw new TalawaGraphQLError({
extensions: {
code: "invalid_arguments",
issues: [
{
argumentPath: ["input", "pluginName"],
message: "Plugin name cannot be empty",
},
],
},
});
}

const plugin = pluginCache.get(input.pluginName.toLowerCase());
const plugin = pluginCache.get(input.pluginName.toLowerCase());

if (!plugin) {
throw new TalawaGraphQLError({
extensions: {
code: "arguments_associated_resources_not_found",
issues: [
{
argumentPath: ["input", "pluginName"],
},
],
},
});
}
if (!plugin) {
throw new TalawaGraphQLError({
extensions: {
code: "arguments_associated_resources_not_found",
issues: [
{
argumentPath: ["input", "pluginName"],
},
],
},
});
}

return plugin;
} catch (error) {
if (error instanceof TalawaGraphQLError) {
throw error;
}
throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}
},
}),
return plugin;
} catch (error) {
if (error instanceof TalawaGraphQLError) {
throw error;
}
throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}
},
})
);
Loading

0 comments on commit 5a86586

Please sign in to comment.