Skip to content

Custom function allows extra params #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ianmacartney
Copy link
Collaborator

Now you can specify extra parameters at the function definition site and use them in the customFunction builder

const myQueryBuilder = customQuery(query, {
  args: {  },
  input: async (ctx, args, { role }: { role: "admin" | "user" }) => {
    const user = await getUser(ctx);
    if (role === "admin" && user.role !== "admin") {
      throw new Error("You are not an admin");
    }
    if (role === "user" && !user) {
      throw new Error("You must be logged in to access this query");
    }
    return { ctx: { user }, args: {} };
  }
});

const myAdminQuery = myQueryBuilder({
  role: "admin",
  args: { },
  handler: async (ctx, args) => {
    // ...
  },
});

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant