nhost / nhost

The Open Source Firebase Alternative with GraphQL.
https://nhost.io
MIT License
7.89k stars 460 forks source link

Add Hasura environment variables to make entire schema camelCase #793

Open joserocha3 opened 2 years ago

joserocha3 commented 2 years ago

Product is awesome so far, excited to get an app into production!

I am wondering if it's possible to set some Hasura environment variables to be able to use camel case naming convention. I can set them in nhost/config.yml for local development, but not via the Nhost console.

It would be great if we could get those variables available in Nhost cloud console, or maybe I am overlooking how to do it?

Cannot set in console:

Screen Shot 2022-07-04 at 10 11 47 PM

This works locally:

metadata_directory: metadata
services:
  hasura:
    version: v2.8.3
    environment:
      HASURA_GRAPHQL_EXPERIMENTAL_FEATURES: naming_convention
      HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION: graphql-default

I can set a graphQL name via the Hasura console, but that only changes the field names, not the entire schema.

Comparison:

Screen Shot 2022-07-04 at 10 23 40 PM
elitan commented 2 years ago

This feature is not enabled yet in the Nhost Dashboard, but it's on our roadmap.

elitan commented 2 years ago

I'll keep this issue open until it's possible to change this setting in the Nhost dashboard. It's an important one.

ttiras commented 2 years ago

i need this too and emailed support.

azlekov commented 2 years ago

Hello, any progress on this?

plmercereau commented 2 years ago

We will also need to double-check how hasura-auth and hasura-storage schema would be impacted. From Beep in Discord:

It seems that hasura-auth uses "hasura-default" style type names, like "authUserSecurityKeys_insert_input" so if I switched to "graphql-default" the hasura-auth graphql queries would fail as the new type name would become "AuthUserSecurityKeysInsertInput".

spakanati commented 1 year ago

Any chance this will be enabled anytime soon? Since nhost made the choice to make all the auth and storage schemas, etc. camelcase it makes this feature more important so that public schemas can match instead of being a mixed case schema

elitan commented 1 year ago

We're actively working on a new approach for project configuration, both internally and with the CLI, which will fix this issue.

gapgag55 commented 1 year ago

Any updates?

elitan commented 1 year ago

Nothing yet. Our target is to have this available before the end of the year.

The reason it's taking so long is that we're reworking how project configuration will work with Nhost, and there are a lot of moving pieces.

dohomi commented 1 year ago

This would be a great addition. How would an existing schema be affected by the change?

beepsoft commented 1 year ago

Nothing yet. Our target is to have this available before the end of the year.

Maybe this year? 😄 And hopefully earlier?

elitan commented 1 year ago

New target: End of March.

I want this too. camelCase is much better.

beepsoft commented 1 year ago

I know it is not trivial because the graphql operations called from hasura-auth, hasura-storage, etc. must take into account whether camelCase naming convention is in use or not. Practically, you need to have two sets of operations everywhere (one with snake_case and one with camelCase), or must somehow convert from one to the other.

elitan commented 1 year ago

Exactly.

Both Auth [PR] and Storage [no PR needed] are prepared and should work with any naming convention.

We're now working on a new way to manage environment variables across our system and infrastructure. Once in place, adding support for new env vars like this will be trivial.

joshuadutton commented 1 year ago

@elitan Any updates on this? I have some projects that I will be putting into production over the next few weeks, and I would really like to be able to switch the naming convention before I do.

dbarrosop commented 1 year ago

This one fell through the cracks, let me revisit it and see if we can implement it. Issue is that we need to make sure that changing this value doesn't break storage/auth services.

dbarrosop commented 1 year ago

Just did some testing and unfortunately hasura-auth breaks when changing the default mode. this is because while auth is configuring the queries and mutations to be camelCase the parameters are automatically set by hasura in either snake_case or camelCase, depending on the naming convention. In order to support this feature we'd need to fix this issue, for instance, by passing the env var to auth and using one format for the arguments or the other.

As lacking this feature shouldn't be a blocker as users can configure manually the exact naming used by each query or mutation fixing auth is low on our priority list but if someone is willing to help fixing this adding support to configure the parameter should be trivial.

joshuadutton commented 1 year ago

@dbarrosop I'm willing to implement it and send you a PR, I just need some guidance:

joshuadutton commented 1 year ago

Both Auth [PR] and Storage [no PR needed] are prepared and should work with any naming convention.

That PR changed auth to access the DB directly and not through GraphQL. When I look at the repo, though, I see that everything is setup to use @graphql-codegen/typescript to generate the Typescript types, including all of the operations with graphql-request. So somebody changed it back.

If you want to move forward with the graphql APIs, you could explicitly name your fields and operations like this: https://hasura.io/docs/latest/schema/postgres/custom-field-names/, but that doesn't cover all of the cases of auto-generation and you would need to abandon some or all of the type generation and have some conditionals to handle the different cases. That's honestly more of a mess.

There are even more options that we could discuss, like accessing auth and files from another Hasura instance through a remote schema, but it looks like you guys already considered these problems and came up with a solution that was already implemented in that PR.

So, which approach do you want to take?

joshuadutton commented 1 year ago

I just did a diff (https://github.com/nhost/hasura-auth/compare/refactor/sql-operations...main), and it looks like most of the support is still there to use pgClient instead of gqlSdk. I could go through and make that change, adding any additional functionality that has been added since the Jan 5th PR. I just want to make sure you support this approach.

dbarrosop commented 1 year ago

That branch was reverted and we are not interested in pursuing that approach. To support different naming conventions what we should probably do instead is just add the ability for hasura-auth to choose between one set of queries/mutations or the other. For instance:

If the naming convention is the default one use:

upsertUsers(on_conflict:....)

If the naming convention is graphql:

upsertUsers(onConflict:....)

/cc @szilarddoro as he may be able to confirm if my approach makes sense or not.

szilarddoro commented 1 year ago

I had to catch up on this, as I was not involved in this discussion earlier. But yes, your approach makes sense to me, David. Although, I'm not sure how the GraphQL codegen would behave if both types of queries were available in the project.

joshuadutton commented 1 year ago

I agree. After thinking about it some more, I think it's best to us Hasura GraphQL APIs, that way we can leverage everything Hasura gives us.

My approach would be this:

joshuadutton commented 1 year ago

As far as codegen goes, whenever some API was changed or added, one would just have to run one codegen configuration pointed to a Hasura instance with one naming convention and then run it again pointed to a Hasura instance with the other naming convention to generate the different types and clients.

joshuadutton commented 1 year ago

@dbarrosop I'm willing to implement it and send you a PR, I just need some guidance:

  • How do I set the env vars when running locally (using nhost up)?
  • How do I configure the auth url so it's pointed to my local instance instead of the Docker container?

I've figured this out: I can just edit .nhost/docker-compose.yaml and then run docker-compose myself. When I run nhost up, .nhost/docker-compose.yaml is overwritten. Is there a way I can use nhost up with a custom configuration?

dbarrosop commented 1 year ago

You should be able to pass environment variables using the .env file. In any case, to develop this feature you can just use the docker-compose file in the hasura-auth repo, which you can start with make dev-env-up.

joshuadutton commented 1 year ago

Thanks! Yes, I really appreciate the tooling you have added for running everything locally and and the automated tests. https://github.com/nhost/hasura-auth/pull/375

joshuadutton commented 1 year ago

@dbarrosop @szilarddoro any feedback on the PR is appreciated. This feature is important to me, and I'm willing to do the work.

dbarrosop commented 1 year ago

I see you and Szilard are already working on it. Just wanted to say thanks for the PR. Once we have cleared that PR and it's been merged and released I will work on making this configurable on our platform.

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

beepsoft commented 11 months ago

I haven't followed the recent nhost developments. Is there any progress in this issues?

dbarrosop commented 11 months ago

There is a PR by a member of the community that is WIP

smeevil commented 10 months ago

Would be nice to see this supported

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

joshuadutton commented 3 months ago

I stopped using NHost due to issues like these (still using Hasura). I came to check up on the progress of things, and I see that this is being addressed in the new auth service written in Go:

@dbarrosop What's the status on it? Is the new auth service live? If not, when is it projected to be?

dbarrosop commented 3 months ago

The "new" auth service is live but some endpoints are still being resolved by the old nodejs code. Unfortunately we don't have an ETA on when the migration will be completed.