Link to home
Start Free TrialLog in
Avatar of Richard Comito
Richard ComitoFlag for United States of America

asked on

Failed to load resource GraphQL/React

I am setting up a simple weather app using React/AWS Amplify/AWS Appsync/GraphQL.

I am getting the following errors when I open the console.

Failed to load resource: https://(appsync ID).appsync-api.us-east-1.amazonaws.com/graphql
net::ERR_NAME_NOT_RESOLVED

and

Uncaught (in promise) 
  1. Object
    1. data: {}
    2. errors: [GraphQLError]
    3. __proto__: Object

I am a noob to React and have not used Javascript in 15 years.  So end-user error I am suspecting.

Here are my questions and code.

1) How do I go about troubleshooting these types of issues in the future?
2) How do I hand off the variable to the query to be used by appysync?
3) How do I resolve the Error just in case I am way off on my assumption?


\\Weather Componant

import React, { Component } from 'react'
import { weatherByCity } from '../graphql/queries'
import { API, graphqlOperation } from 'aws-amplify'




class DisplayWeather extends Component {

    componentDidMount = async () => {
        this.getWeather()
    }

    getWeather = async () => {

            const result = await API.graphql(graphqlOperation(weatherByCity))
            console.log('weatherByCity', JSON.stringify(result))

    }

    render() {
        return (
            <div>
                data
            </div>
        )
    }
}

export default DisplayWeather



Open in new window


//Query.js
/* eslint-disable */
// this is an auto generated file. This will be overwritten

export const weatherByCity = /* GraphQL */ `
  query WeatherByCity($city: String!) {
    weatherByCity(city: $city) {
      timestamp
      location
      condition
      description
      temperature
      pressure
      humidity
      wind_speed
      wind_direction
      cloud_cover
      rain_volume
      snow_volume
    }
  }
`;



Open in new window


Any advice is welcome.  Thank you in advance.

Rich

SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Comito

ASKER

Thanks,  I didn't even think to do a ping.

I did the ping and got back. "Ping request could not find host https://(appsync id).appsync-api.us-east-1.amazonaws.com/graphql. Please check the name and try again."

I went into AppSync and noticed that the API URL in my AppSync API and the API URL in the aws-export.js were both different.  I changed the aws-export.js to match and confirmed that my APIKey is up-to-date.  That seems to have fixed the first error.
(on a side note: I did try to ping the good API URL that is working, and I received the same error.  Do you know why that is?)

But I am still getting the second error.  I know the page needs an input window and an onClick event button.  But is there an easy way to pass the variable in the code while I am testing?

Thank you again,

Rich
Got it.

Same reply.

Rich
ok so you did not put the right URL
you probably start from a tutorial, could you provide the link?

No. I was using a different AppSync URL for another API that I was switching over from.
(I am not that much of a noob)

The problem was fixed when I noticed I was using the old URL that I had deleted, plus my API key was expired, so I needed to replace that.

I got the appsync working when I realized I was using the old URL(Thank you for that.  I wasn't even thinking to look there.).

I just wanted to move on to ask for advice on troubleshooting React, AWS issues, and tips as I move forward.

I am DBA by trade and have been doing that for over twenty years.  T-SQL, MS SQL Servers no problem.

React is a different story. I have been working with React for about six months, but that is along with learning AWS Control Tower, Amplify, Route 53, and ect ....  So I cannot focus as well as I would like.

My Javascript is weak, but that is what I am working on.  In the past, I used to build Ticketing systems in ASP Classic and VB.  Yes, I am that old.  I can remember when .net came out in 2007.  So I do understand far more than I can express at times.

Thank you for your help!

Rich
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial