Closed mattiLeBlanc closed 7 months ago
Note: VS Code can deduce the output, but it is not strictly typed if I keep the return type empty. ergo:
getAuthSession() {
return from(fetchAuthSession(());
}
Actually, there are more interfaces not exported, like GraphQLOptions
and GraphQLResult
. I would lile to use them in my code, like this:
type queryInput = {
statement: string;
params: { [key: string]: any };
type: string;
iam: boolean;
}
@Injectable({
providedIn: 'root'
})
export class ApiService {
private client = generateClient();
graphql({ statement, params, type, iam = false} : queryInput) {
const payload: GraphQLOptions = {
query: statement,
authMode: iam ? 'iam' : 'userPool',
}
if (params) {
payload.variables = params;
}
return from<GraphQLResult>(this.client.graphql(payload));
}
}
Actually,
GraphQLResult
seems to be there, but not GraphQLOptions
, however it is declared next to GraphQLResult
. Is that my VS Code being confused?
I can confirm. As a workaround, for the time being, we defined this in place of AuthSession
:
import { fetchAuthSession } from "aws-amplify/auth";
type AmplifyAuthSession = Awaited<ReturnType<typeof fetchAuthSession>>;
Hi @mattiLeBlanc thank you for opening this issue. We are currently discussing this internally and will follow up soon.
Hey, @mattiLeBlanc 👋. Wanted to follow up with you now that this should be implemented. It looks like we introduced this feature in PR #13037 and it's available in v6.0.19 of Amplify. I think you opened this issue just a week or so before the PR was merged 😄.
I'll close this out for now, but feel free to reply back if v6.0.19+ doesn't offer the support you were looking for. Thanks!
@cwomack Thanks for the update and the work! I can't try it yet because I stuck in upgrading to Amplify 6 due to a build issue in Angular in relation to PNPM (https://github.com/aws-amplify/amplify-js/issues/13054). I am looking playing with NX mono repo without pnpm and that is looking promising so hopefully I can use A6 soon.
We have this need for StorageGetUrlOutput
as well.
Has this been resolved in a later version?
Hoping this thread is an acceptable place to raise this issue as it seems closely related.
The following types and interfaces are not exported from aws-amplify/auth
. It appears to be causing a TS error when calling fetchAuthSession()
inside a function which uses an inferred type for the return. TS struggles to infer the type as it JsonObject (in this case) is not available to it.
Exported variable fooFunc has or is using name 'JsonObject' from external module "[node_modules]/@aws-amplify+core@6.4.4/node_modules/@aws-amplify/core/dist/esm/singleton/Auth/types" but cannot be named.ts(4023)
JwtPayloadStandardFields
JsonPrimitive
JsonArray
JsonObject
Is there a reason these aren't exported? I'm happy to raise a separate issue for this or just a PR to export them. Having tried to work around this issue through type coercion and type casting for 2 days, I'm also happy to be told I'm doing something wrong and pointed in a different direction.
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
Interface AuthSession is not exported from
aws-amplify/auth/
types.Expected behavior
When using
I want to be able to return a typed response of my function
getAuthSession
. AuthSession is not exported atm because it is part ofPromise<import("../Auth/types").AuthSession>;
Reproduction steps
install amplify 6 and create a function in Angular returning the authSession
Code Snippet
getAuthSession(): Observable {
return from(fetchAuthSession());
}
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots