You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The API.ts codegen is very useful for inputs, but is not as useful for typing results of API.graphql(graphqlOperation(createSomeObject, {})). API.grapqhl returns a GraphQLResult or an Observable -- but it isn't able to tell which one it will return and neither are generic, which causes typing challenges.
Describe the solution you'd like
import { CreateSomeObjectMutation, OnCreateSomeObject } from './API';
const result = API.graphql<Mutation, CreateSomeObjectMutation>(graphqlOperation(createSomeObject, {...}))
// None of the below code should throw a type error. It should expect the object to have this shape.
if(result.data) {
result.data.createSomeObject
} else {
console.log(result.errors);
}
const { fieldA } = result.data.createSomeObject;
const observableResult = API.graphql<Subscription, OnCreateSomeObject>(graphqlOperation(onCreateSomeObject, {...}))
observableResult.then(....???... )
Describe alternatives you've considered
Type casting the result. This works but is less declarative IMO and requires more code.
Additional context
The text was updated successfully, but these errors were encountered:
const response: GraphQLResult<CreateTenantMutation> = await API.graphql(options) as GraphQLResult<CreateTenantMutation>
seems to work for me as an interim fix, but it would me much nicer as a generic
We do not have any API.graphql code generation in amplify codegen except for angular, where we do have a type casting for each graphql operation. Could you provide more contexts about how the codegen can help you on your use case? For now this looks like an issue for amplify-js library. If this is the case, I will ask js developers for help.
Is your feature request related to a problem? Please describe.
The API.ts codegen is very useful for inputs, but is not as useful for typing results of
API.graphql(graphqlOperation(createSomeObject, {}))
. API.grapqhl returns a GraphQLResult or an Observable -- but it isn't able to tell which one it will return and neither are generic, which causes typing challenges.Describe the solution you'd like
Describe alternatives you've considered
Type casting the result. This works but is less declarative IMO and requires more code.
Additional context
The text was updated successfully, but these errors were encountered: