Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

amazon web services - No graphql endpoint provided

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!!

question from:https://stackoverflow.com/questions/66045793/no-graphql-endpoint-provided

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Right, I figured it out:

  1. add this to your aws-exports:

"aws_appsync_graphqlEndpoint": "https://ENDPOINT_GRAPHQL.com/graphql", "aws_appsync_region": "eu-west-1", "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",

  1. This is how you query:

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)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...