pokeapi icon indicating copy to clipboard operation
pokeapi copied to clipboard

remove pokemon_v2_ prefix from GraphQL keys

Open Naramsim opened this issue 9 months ago • 5 comments

I'd like to have a cleaner way to build GraphQL queries. Currently all keys are prefixed with a pokemon_v2_ string. This is because Hasura tracks postgres tables and our tables have that prefix.

It would be cool to strip it away so to be able to build cleaner queries like the one below:

query samplePokeAPIquery {
  pokemonspecies(
    where: {generation: {name: {_eq: "generation-iii"}}}
    order_by: {id: asc}
  ) {
    name
    id
  }
  generation {
    name
    pokemonspecies_aggregate {
      aggregate {
        count
      }
    }
  }
}

instead of the currently working:

query samplePokeAPIquery {
  gen3_species: pokemon_v2_pokemonspecies(
    where: {pokemon_v2_generation: {name: {_eq: "generation-iii"}}}
    order_by: {id: asc}
  ) {
    name
    id
  }
  generations: pokemon_v2_generation {
    name
    pokemon_species: pokemon_v2_pokemonspecies_aggregate {
      aggregate {
        count
      }
    }
  }
}

Naramsim avatar Jun 03 '25 08:06 Naramsim

@PraaneshSelvaraj or you could investigate this

Naramsim avatar Jun 03 '25 08:06 Naramsim

Hmm this is interesting, I guess Hasura has no way to set an alias for tables?

phalt avatar Jun 03 '25 08:06 phalt

Tried in past but with no luck, maybe with newer version they added a way to achieve it

Naramsim avatar Jun 03 '25 08:06 Naramsim

Hey, we can set custom names for each table in Hasura. BUt, if we do this directly in the console, we have to manually rename them with every deployment to both our dev and production environments.

To avoid manually renaming them, we can maintain the Hasura metadata within our git repo. This ensures that the custom names are automatically loaded saving us from manual configuration every time we spin up a hasura server.

PraaneshSelvaraj avatar Jun 09 '25 16:06 PraaneshSelvaraj

Hey, Actually I found that configuration files under the graphql directory. I think we can setup custom names over here for each table. Maybe I will try that.

PraaneshSelvaraj avatar Jun 09 '25 17:06 PraaneshSelvaraj