Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed NhostClient #2623

Open
janat08 opened this issue Mar 28, 2024 · 6 comments
Open

Typed NhostClient #2623

janat08 opened this issue Mar 28, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@janat08
Copy link

janat08 commented Mar 28, 2024

Is your feature request related to a problem? Please describe.
I'm unclear as to how to do codegen to have typed gql requests.

Describe the solution you'd like
Prisma lets you generate DB schema and types from schema config files in repo. But by and large I can't be asked to switch gql package with types support because I can't tell how to pass in adminSecret, or what the endpoint looks like, etc.

Describe alternatives you've considered
I considered using graphql-request package instead, and applying some codegen preset thing for my use case (typed gql). The documentation is bad and linked to low-level implementation at first.

Additional context
I'm using nhost for server-side, so I just care about types with none of the other bells and whistles.

@janat08 janat08 added the enhancement New feature or request label Mar 28, 2024
@janat08
Copy link
Author

janat08 commented Mar 28, 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',
    },
  },
});

@dbarrosop
Copy link
Contributor

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.

@janat08
Copy link
Author

janat08 commented Apr 3, 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.

@janat08
Copy link
Author

janat08 commented Apr 7, 2024

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

@dbarrosop
Copy link
Contributor

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

@janat08
Copy link
Author

janat08 commented Apr 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants