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

Make useGraphQLQuery support error codes #1220

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

goodoldneon
Copy link
Contributor

@goodoldneon goodoldneon commented Mar 7, 2024

Description

Make useGraphQLQuery support error codes returned by our GraphQL API.

This change will not break any code, since consumers were already expecting at Error object. We're now returning a custom object whose class extends Error

Motivation

https://linear.app/inngest/issue/INN-2863/added-error-code-support-to-usegraphqlquery

Testing

I made this change to the GraphQL API:

diff --git a/api/gql/resolver/app.go b/api/gql/resolver/app.go
index 728c9f272..56c04f2f8 100644
--- a/api/gql/resolver/app.go
+++ b/api/gql/resolver/app.go
@@ -12,6 +12,7 @@ import (
 	"github.com/tonyhb/datos/pkg/applogic/workspaces"
 	"github.com/tonyhb/datos/pkg/enums"
 	"github.com/tonyhb/datos/pkg/objects/osql"
+	"github.com/vektah/gqlparser/v2/gqlerror"
 	"github.com/volatiletech/null/v8"
 	"github.com/volatiletech/sqlboiler/v4/queries/qm"
 )
@@ -23,6 +24,13 @@ func (r *appResolver) LatestSync(
 	obj *osql.App,
 	status *enums.DeployStatus,
 ) (*osql.Deploy, error) {
+	return nil, &gqlerror.Error{
+		Message: "my message",
+		Extensions: map[string]interface{}{
+			"code": "MY_CODE",
+		},
+	}
+
 	query := osql.Deploys(
 		osql.DeployWhere.AppID.EQ(null.StringFrom(obj.ID.String())),
 		qm.OrderBy(osql.DeployColumns.CreatedAt+" DESC"),

And then observed that the correct error was returned on the apps page

Type of change (choose one)

  • Chore (refactors, upgrades, etc.)
  • Bug fix (non-breaking change that fixes an issue)
  • Security fix (non-breaking change that fixes a potential vulnerability)
  • Docs
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)

Checklist

  • I've linked any associated issues to this PR.
  • I've tested my own changes.

Check our Pull Request Guidelines

Copy link

linear bot commented Mar 7, 2024

Copy link

vercel bot commented Mar 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ❌ Failed (Inspect) Apr 15, 2024 8:39pm

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

Successfully merging this pull request may close these issues.

None yet

2 participants