Created
May 17, 2024 12:14
-
-
Save sibelius/efae6b586d586d14404f8aabdc505b89 to your computer and use it in GitHub Desktop.
metabase graphql resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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