Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created May 17, 2024 12:14
Show Gist options
  • Save sibelius/efae6b586d586d14404f8aabdc505b89 to your computer and use it in GitHub Desktop.
Save sibelius/efae6b586d586d14404f8aabdc505b89 to your computer and use it in GitHub Desktop.
metabase graphql resolver
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;
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment