-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(GraphQL): Webhooks on add/update/delete mutations (GRAPHQL-1045) #7494
Conversation
…ebhooks # Conflicts: # graphql/schema/wrappers.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 74 of 74 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @abhimanyusinghgaur, @manishrjain, @vmrajas, and @vvbalaji-dgraph)
graphql/resolve/mutation_rewriter.go, line 819 at r1 (raw file):
uids := make([]uint64, 0, len(uidSlice)) if len(uidSlice) > 0 {
this if block is not required
graphql/resolve/webhook.go, line 110 at r1 (raw file):
b, err := json.Marshal(payload) if err != nil { // don't care to send the payload if there are JSON marshalling errors
We should log the error using glog.Error in V3 level
graphql/resolve/webhook.go, line 117 at r1 (raw file):
headers.Set("Content-Type", "application/json") // don't care for the response/errors, if any. _, _ = schema.MakeHttpRequest(nil, http.MethodPost, x.Config.GraphQL.GetString("lambda-url"),
let's log the error if its non-nil or if response code is not a success
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a way to override this behavior using a key that is part of extensions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @abhimanyusinghgaur, @manishrjain, @vmrajas, and @vvbalaji-dgraph)
…ebhooks # Conflicts: # graphql/e2e/schema/apollo_service_response.graphql # graphql/resolve/mutation_rewriter.go # graphql/schema/dgraph_schemagen_test.yml # graphql/schema/gqlschema.go # graphql/schema/gqlschema_test.yml # graphql/schema/testdata/apolloservice/output/auth-directive.graphql # graphql/schema/testdata/apolloservice/output/custom-directive.graphql # graphql/schema/testdata/apolloservice/output/extended-types.graphql # graphql/schema/testdata/apolloservice/output/generate-directive.graphql # graphql/schema/wrappers.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The mutation_rewriter.go part looks good to me.
Just added few nits.
t.Run("entitites Query on extended type with key field of type String", entitiesQueryWithKeyFieldOfTypeString) | ||
t.Run("entitites Query on extended type with key field of type Int", entitiesQueryWithKeyFieldOfTypeInt) | ||
t.Run("entities Query on extended type with key field of type String", entitiesQueryWithKeyFieldOfTypeString) | ||
t.Run("entities Query on extended type with key field of type Int", entitiesQueryWithKeyFieldOfTypeInt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -341,7 +341,8 @@ type Region { | |||
district: District | |||
} | |||
|
|||
type District { | |||
type District @lambdaOnMutate(add: true, update: true, delete: true) { | |||
dgId: ID! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Indentation seems off. Likely due to different tab spaces being used.
graphql/e2e/directives/script.js
Outdated
self.addWebHookResolvers({ | ||
"District.add": districtWebhook, | ||
"District.update": districtWebhook, | ||
"District.delete": districtWebhook, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Line at end of file.
graphql/e2e/normal/script.js
Outdated
self.addWebHookResolvers({ | ||
"District.add": districtWebhook, | ||
"District.update": districtWebhook, | ||
"District.delete": districtWebhook, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Extra line at end of file.
if err != nil { | ||
glog.Errorf("Error occured while aborting transaction: %s", err) | ||
glog.Errorf("Error occurred while aborting transaction: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -263,12 +263,12 @@ func (xidMetadata *xidMetadata) isDuplicateXid(atTopLevel bool, xidVar string, | |||
// simply ignored. | |||
// If it is found out that the Person with id 0x123 does not exist, the corresponding | |||
// mutation will fail. | |||
func (mrw *AddRewriter) RewriteQueries( | |||
func (arw *AddRewriter) RewriteQueries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
graphql/schema/gqlschema_test.yml
Outdated
type Question implements Post @lambdaOnMutate(add: true, update: true) { | ||
id: ID! | ||
questionText: String | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Line at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 54 of 91 files reviewed, 6 unresolved discussions (waiting on @manishrjain, @pawanrawal, @vmrajas, and @vvbalaji-dgraph)
graphql/resolve/mutation_rewriter.go, line 819 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
this if block is not required
Done.
graphql/resolve/webhook.go, line 110 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
We should log the error using glog.Error in V3 level
Done.
graphql/resolve/webhook.go, line 117 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
let's log the error if its non-nil or if response code is not a success
Done.
…#7494) Please see the [RFC](https://discuss.dgraph.io/t/webhook-lambda-on-add-update-delete-mutations/12904) for more details. (cherry picked from commit 348119e) # Conflicts: # graphql/schema/testdata/schemagen/output/interface-with-id-directive-and-ID-field.graphql
…#7494) (#7616) Please see the [RFC](https://discuss.dgraph.io/t/webhook-lambda-on-add-update-delete-mutations/12904) for more details. (cherry picked from commit 348119e) # Conflicts: # graphql/schema/testdata/schemagen/output/interface-with-id-directive-and-ID-field.graphql
…#7494) (#7616) Please see the [RFC](https://discuss.dgraph.io/t/webhook-lambda-on-add-update-delete-mutations/12904) for more details. (cherry picked from commit 348119e) # Conflicts: # graphql/schema/testdata/schemagen/output/interface-with-id-directive-and-ID-field.graphql
Please see the RFC for more details.
This change is