How to exploit the return of a resolver?


My question is maybe basic but I doesn’t how to get the return from my resolver although I have the hello word code example for confluence macro.

my resolvers.js is

import Resolver from '@forge/resolver';
import api, { route } from "@forge/api";

// XRAY API base URL
const XRAY_API_BASE = '';
const resolver = new Resolver();

resolver.define('getToken', async () => {
  console.log("Making XRAY GraphQL API to get token...");
  const response = await api.fetch(
    `${XRAY_API_BASE}/authenticate`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'

console.log("Response", await response.json())
//return await response.json()
return 'world'

export const handler = resolver.getDefinitions();

and my index.jsx

import React, { useEffect, useState } from 'react';
import ForgeReconciler, { Text } from '@forge/react';
import { invoke } from '@forge/bridge';
const result = null;

const App = () => {

useEffect(() => {
}, []);

  console.log("Log --- ", result);
    return <Text>Hello {result}</Text> 


    <App />

My goal is to have

return Hello world

result variable is the result of getToken. and getToken return world

Do you have advice to catch error on API call ?

Hello @ThibautFAURE,

I think this area needs to be updated to something like:

const App = () => {

  const [result, setResult] = useState(null);

  useEffect(() => {
    // "then" accepts a function to run once the promise is fulfilled
    // the "then" will now call the function "setResult" which sets the value of "result"
  }, []);

  console.log("Log --- ", result);
  return <Text>Hello {result}</Text> 

Kindly try it out and let us know how it goes.



Thank you very much it’s works

1 Like

Happy to help and glad to know you got it working, @ThibautFAURE :slight_smile:

1 Like