Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created May 17, 2024 12:14

Revisions

  1. sibelius created this gist May 17, 2024.
    34 changes: 34 additions & 0 deletions metabaseEmbedResolver.spec.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    export const metabaseEmbedResolver = {
    metabaseEmbedUrl: {
    type: GraphQLString,
    args: {
    question: {
    type: new GraphQLNonNull(GraphQLString),
    },
    params: {
    type: GraphQLString,
    },
    },
    resolve: (obj, args, context) => {
    if (!isLoggedIn(context)) {
    return NullConnection;
    }

    const payload = {
    resource: { question: parseInt(args.question, 10) },
    params: args.params ? JSON.parse(args.params) : {},
    exp: Math.round(Date.now() / 1000) + 10 * 60, // 10 minute expiration
    };

    const token = jwt.sign(payload, METABASE_SECRET_KEY);

    const iframeUrl =
    `${METABASE_SITE_URL
    }/embed/question/${
    token
    }#bordered=true&titled=true`;

    return iframeUrl;
    },
    },
    };