hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.76k forks source link

idempotent metadata api #3959

Open jjangga0214 opened 4 years ago

jjangga0214 commented 4 years ago

Hi,

I think some metadata APIs are good to be treated idempotent.

For instance, add_computed_field responds 400 already-exists error, if I try to add an existing computed field. I understand this is to prevent mistakenly overriding the existing fields.

To ignore this, currently, one should add explicit error handling, something like

if (
  !(
    err.response.status === 400 &&
    err.response.data.code === "already-exists"  
  )
    ) {
// ...
}

However, for a practical point of view, considering it as an idempotent action would be a little more convenient. For one of examples, someone might want to run add_computed_field as migration phase(including metadata API calling, not limited to Hasura's migration feature) to make it simpler.

If there are many different Hasura instances on different environments, he or she might just not want to think about if "this hasura" or "that hasura" already has the computed field or not. So one might want to treat it more like declarative configuration (e.g. k8s manifest).

If this makes sense, I want to hear how others think about it.

Thanks.

rikinsk commented 4 years ago

This is something I've had trouble handling as well. All track APIs should be idempotent.

tirumaraiselvan commented 4 years ago

Turns out with v2 metadata workflow (https://github.com/hasura/graphql-engine/pull/3859) this might not be an issue because the full metadata would be applied.

rikinsk commented 4 years ago

It's still relevant for projects using the metadata API as a way to configure Hasura. e.g. the console

beepsoft commented 4 years ago

I have a small library (https://github.com/beepsoft/hasuraconf), which generates Hasura metadata API calls based on JPA and other annotations in Java, so this idempotent behaviour here would be really helpful.

ntx-ben commented 4 years ago

Running into this issue while sending off 'add_remote_schema' requests to the query API in k8s environment where I was assuming an already existing remote schema would not give out a HTTP 400 error code.

beepsoft commented 4 years ago

@tirumaraiselvan I've seen in the last community call that there's a lot going on with Hasura metadata handling.

Is this idempotent metadata api fix still on the roadmap?

Solving this would help with all the headaches we still have with managing many remote schemas in Hasura.

beepsoft commented 3 years ago

@tirumaraiselvan Any news on this issue? Thanks!