I'm having trouble with using he graphQL from AWS.
I can successfully login and confirm the user with Cognito as I can see it in the console.
Sign in with Cognito:
async signIn(email, password) {
try {
//sign in the user
const user = await Auth.signIn(email, password);
AlertHelper.show('info', 'yups', user);
}
//If not a user then display message
catch (error) {
AlertHelper.show("warn", "User not found", "Please create an account");
}
}
Returns a successful message then I call another function to call the graphQL api:
async check() {
try {
const userInfo = await Auth.currentAuthenticatedUser({bypassCache:true})
console.log("User info: ",userInfo)
//If there is a user
if(userInfo){
const userData = await API.graphql(graphqlOperation(getUser));
console.log("User Data: ",userData);
}
}
catch (err) {
console.log('Error: ', err)
}
}
Here is the error even though the user info is correct:
errors: [ [GraphQLError: No graphql endpoint provided.] ] }
Here is my AWS Exports:
const awsmobile = {
"aws_project_region": "eu-west-1",
"aws_cognito_identity_pool_id": "eu-west-1:xxxxxxxxxxxxxxxxxxxxxx",
"aws_cognito_region": "eu-west-1",
"aws_user_pools_id": "eu-west-1_xxxxxxxxx",
"aws_user_pools_web_client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"oauth": {}
};
export default awsmobile;
Get User:
export const getUser = /* GraphQL */ `
query GetUser($id: ID!) {
getUser(id: $id) {
id
name
coins
description
createdAt
updatedAt
}
}
`;
Im tearing my hair out here please help!!
Right, I figured it out:
"aws_appsync_graphqlEndpoint": "https://ENDPOINT_GRAPHQL.com/graphql", "aws_appsync_region": "eu-west-1", "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
imports:
import * as mutations from '../../../graphql/mutations';
import * as queries from '../../../graphql/queries';
Function:
async check() {
try {
const userInfo = await Auth.currentAuthenticatedUser({bypassCache:true})
console.log("User info: ",userInfo)
//If there is a user
if(userInfo){
const oneTodo = await API.graphql({ query: queries.getUser, variables: { id: '111' }});
console.log("one todos: ",oneTodo); // result: { "data": { "listTodos": { "items": [/* ..... */] } } }
}
}
catch (err) {
console.log('error: ', err)
}
}