frankcollins3 / Next-Water-App

Happy, Healthy Water Cycling App that tracks user/human fluid intake.
https://next-water-app.vercel.app
1 stars 0 forks source link

Learning GraphQL for Next with ChatGPT [10:26pm] #23

Closed frankcollins3 closed 12 months ago

frankcollins3 commented 12 months ago

attempting to do: learning a bit about a few of the GraphQL libraries like Apollo Server and Graphql-Request. Perform a minimum viability pokeAPI (https://pokeapi.co/api/v2/pokemon/ditto) fetch through Graphql-request // pokeAPI not relevant to the app outside of being the first data call to make sure everything is up and running.

error: chat keeps spitting out Apollo code when the app calls for the use of a very simple query system that hits prisma. // I was going to post the whole conversation it's a lot to read and nobody will probably read it.

from pokeAPI itself: PokeAPI proudly announces Beta support for GraphQL. Access our free console at beta.pokeapi.co/graphql/console and take a look at the documentation // this GraphQL purposed format of pokedata was clouding chats ability to think abstractly. // it could not think of another workaround that wasn't the right tool for the right job. // it couldn't use wrong tool for right job. (i was testing http on graphql-request which is not http but there is workaround)

proposed approach: long story made short:chat woke up from its stupor upon being led to the correction that:

allDBsettings: {
  type: new GraphQLList(SettingsType),
  // type: GraphQLString,
  description: 'List of Settings',
  resolve: async () => {
     let bucket = [];
     **let settings = await prisma.settings.findMany()**
     let set1 = settings[0]
     return { id, weight, height, age, reminder, start_time, end_time, reminder, activity, users_id } = settings 
  }
},   

this code could be performed with: npm i graphql-request let settings = await prisma.settings.findMany()

once chatGPT admitted this code it allowed me to correct it that:

we could then use such a query as a workaround to bypass it's limitation of only knowing the conformity to convention

allPokemon { let url = 'http://pokeapi.co/api/v2/pokemon/` let pokedata = await axios.get(url) return pokedata }

frankcollins3 commented 12 months ago

excerpt: not a finance guy but in rich dad poor dad. 2 perspectives abundance: how can I lack: i can't.

chatGPT was essentially playing in the world of: "those without/poor say I can't" whereas "those with/rich say how can I"

how can I express an HTTP data call in a querylibrary that doesn't run http? run an HTTP method like axios within such a data call from that limited querylibrary [10:31pm]

frankcollins3 commented 12 months ago

instead of adding issue or committing since i'm using downversioned next that's gonna add hundreds of commits for same functions already committed in water app:

const axios = require('axios');
const { GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLSchema } = require('graphql');

// Define the PokemonType GraphQLObjectType
const PokemonType = new GraphQLObjectType({
  name: 'Pokemon',
  fields: {
    name: { type: GraphQLString },
    id: { type: GraphQLInt },
  },
});

// Define the root Query
const RootQuery = new GraphQLObjectType({
  name: 'RootQueryType',
  fields: {
    getPokemon: {
      type: PokemonType,
      resolve: async () => {
        try {
          const response = await axios.get('https://pokeapi.co/api/v2/pokemon/ditto');
          const { name, id } = response.data;
          return { name, id };
        } catch (error) {
          console.error(error);
          throw new Error('Failed to fetch Pokemon data');
        }
      },
    },
  },
});

// Define the schema
const schema = new GraphQLSchema({
  query: RootQuery,
});

// Example usage
const query = '{ getPokemon { name, id } }';

graphql(schema, query)
  .then((result) => {
    console.log(result.data);
  })
  .catch((error) => {
    console.error(error);
  });

// export const testfunc = () => {
//     let test:string = "my_test"
//     console.log(test);
//     return `test-concatenated: I failed ${test}`
// }

// export default testfunc

chat forgot to import graphql here and it said couldn't find. almost looked into versions and alternate examples before testing out whether it just needed import which it did. const { GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLSchema, graphql } = require('graphql');

[2:08am]

frankcollins3 commented 12 months ago

apollo-server-micro is now @apollo/server [2:36am]

frankcollins3 commented 12 months ago

@apollo/server-micro not found mate:

ChatGPT Apologies for the confusion. It appears that there might have been a misunderstanding. As of my knowledge cutoff in September 2021, Apollo Server does not provide a specific package named @apollo/server-micro.

[2:50am]

Just like there is more to typescript than: let myshirt:string = "blue shirt";

(what I know in GraphQLExpress which is now GraphQLHTTP) there is more to GraphQL then:

Let UsersType = GraphQLObjectType( {} )

  allDBusers: {
    type: new GraphQLList(UsersType),
    description: 'List of Users from Postgres & Prisma',
    resolve: async () => {
      let allusers = await prisma.users.findMany()
      return { id, googleId, icon, username, email, password, age } = allusers
    }
  },