GithubHelp home page GithubHelp logo

Typed NhostClient about nhost HOT 6 OPEN

janat08 avatar janat08 commented on July 4, 2024
Typed NhostClient

from nhost.

Comments (6)

janat08 avatar janat08 commented on July 4, 2024

I've now tried apollo with official integration with react that didn't work for me as I don't use react. I also attempted trying to pass in jwt bearer token and that resulted in jwt error when using apollo directly. I used env variable for hasura endpoint as a link.


const httpLink = createHttpLink({
  uri: 'https://ybjelsmfvjhtzjaspgnr.graphql.eu-central-1.nhost.run/v1',
});

const authLink = setContext((_, { headers }) => {
  // Get the authentication token from local storage if it exists
  const token = 'abc';
  // Return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : "",
    }
  }
});

const nhost = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
  defaultOptions: {
    query: {
      fetchPolicy: 'no-cache',
    },
    watchQuery: {
      fetchPolicy: 'no-cache',
    },
  },
});

from nhost.

dbarrosop avatar dbarrosop commented on July 4, 2024

I guess you could check how we do it in our dashboard:

https://github.com/nhost/nhost/blob/main/dashboard/graphql.config.yaml
https://github.com/nhost/nhost/blob/main/dashboard/package.json#L13

We also wrote a blog post about this topic some time ago:

https://nhost.io/blog/graphql-code-generator-maximizing-graphql-development-typescript

Hopefully this sets you in the right track.

from nhost.

janat08 avatar janat08 commented on July 4, 2024

I don't use react. Reason why that I mentioned prisma is that I believe that it must do things in a way that lets you get types without relying on some react preset however much I'm find with using apollo which is also pretty react. Can you at very least bother documenting how I'm suppose to connect to nhost WITHOUT the react or your nhost client that WILL NOT support typescript.

from nhost.

janat08 avatar janat08 commented on July 4, 2024

I still can't really tell how to use anything but nhost react because the API is undocumented.

from nhost.

dbarrosop avatar dbarrosop commented on July 4, 2024

While I understand we don't provide a tutorial using the SDK, you can find the JS/TS SDK reference documentation here:

https://docs.nhost.io/reference/overview#client-libraries

For instance:

https://docs.nhost.io/reference/javascript/auth/change-email

And you can find the API documentation here:

https://docs.nhost.io/reference/auth/sign-up-email-and-password

from nhost.

janat08 avatar janat08 commented on July 4, 2024

from nhost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.