frankcollins3 / PHPokedex

react concepts
0 stars 0 forks source link

👎 resolve()=>return data.results | 👍 return [ {name: '...'} ] same handwritten arr from logs works [11:39am] #23

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

Screen Shot 2023-05-08 at 11 33 46 AM

Screen Shot 2023-05-08 at 11 33 56 AM

Screen Shot 2023-05-08 at 11 34 00 AM

react && express are linked up. express && graphQL is linked up.

the pokemon data that is returned from the browser as: returndata.data.results is returning a "not iterable" err in graphQL 👎 resolve: () => { return pokemondata.data.results }

👍 taking the data from the browser (pokemondata.data.results) and using making an array of that data works The output is shown in graphQL as the exact same output from the terminal. (api/pokemon?limit=20) but cut off at 13.

This situation seems to say the problem is in getting graphQL to accept: [] {name:} the objects within the array.

first proposed solution:

1) working with logs and setting the array to have the objects. (which I thought the array returned from data.results did) 2) arr.join() see about combining the object data with .join() of some sort.

frankcollins3 commented 1 year ago

Screen Shot 2023-05-08 at 12 28 17 PM

let bucket = new Array() || [] let pokemon = await axios.get(https://pokeapi.co/api/v2/pokemon?limit=151) let data = pokemon.data.results await data.forEach(data => bucket.push({name: data.name, id: bucket.length + 1 })) if (bucket) { return bucket }

to make a single object out of every instance of data with the keys defined as constrained by:

const PokemonType = new GraphQLObjectType({ name: 'Pokemon', description: "This is a pokemon with data populated from the API", fields: () => ({ // id: { type: new GraphQLNonNull(GraphQLInt) }, name: { type: new GraphQLNonNull(GraphQLString) }, id: { type: new GraphQLNonNull(GraphQLInt) } // I dont want it to be non nulled. it can be nulled to allow for quicker iteration of addPokemon

})

})

[12:29pm]