I have a service.ts
that is adding additional data to the one that were previously fetched from Apollo GraphQL. But the data doesn't matter. What matter is - how to grab the returned value?
class TestService implements TestServiceInterface {
public async fetch(): Promise<any> {
const result = await apolloClient.query({
query: gql`
query Query {
Test{
test
}
}
}
}
`,
})
return {
graphTitle: "Test",
graph: "LINE",
};
}
}
export interface TestServiceInterface {
fetch(): Promise<any>;
}
Fetch is done properly, and in my case I couldn't use useQuery
and I have to fetch the data outside the React component.
My question is: how to pass the returned value to another .ts file? I tried something like:
export const TestData = async () => { const dataToSet = await TestService.fetch(); }
but the value returned is a promise:
Promise {
"_U": 0,
"_V": 0,
"_W": null,
"_X": null,
}
How to resolve it? How to grab the returned value from TestService in another .ts file?
EDIT 1:
const test = TestService.fetch()
export const TestService = (async () => {
return await test
})()
gives me almost what I need, but now in the component I receive (and still an error):
Promise { "_U": 0, "_V": 1, "_W": Object { **correct values here** }
How to grab the values from inside of the object?