-
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): GraphQL now has lambda resolvers #6574
Conversation
…ambda # Conflicts: # graphql/schema/testdata/schemagen/output/filter-cleanSchema-all-empty.graphql # graphql/schema/testdata/schemagen/output/filter-cleanSchema-circular.graphql # graphql/schema/testdata/schemagen/output/filter-cleanSchema-custom-mutation.graphql # graphql/schema/testdata/schemagen/output/filter-cleanSchema-directLink.graphql
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.
Let's create a documentation ticket on how open source users can make use of this.
feel free to merge after adding some more comments where requested
Reviewed 27 of 66 files at r1.
Reviewable status: 27 of 66 files reviewed, 9 unresolved discussions (waiting on @abhimanyusinghgaur, @manishrjain, @MichaelJCompton, @pawanrawal, and @vvbalaji-dgraph)
dgraph/cmd/alpha/run.go, line 201 at r1 (raw file):
flag.Bool("graphql_extensions", true, "Set to false if extensions not required in GraphQL response body") flag.Duration("graphql_poll_interval", time.Second, "polling interval for graphql subscription.") flag.String("graphql_lambda_url", "", "URL of lambda functions for custom GraphQL resolvers")
lambda server that implements custom GraphQL Javascript resolvers.
graphql/e2e/common/lambda.go, line 95 at r1 (raw file):
testutil.CompareJSON(t, expectedResponse, string(resp.Data)) // TODO: this should work. At present there is a bug with @custom on interface field resolved
Create a bug report for this.
graphql/e2e/normal/script.js, line 7 at r1 (raw file):
async function authorsByName({args, dql}) { const results = await dql.query(`{
Can we provide variables for a DQL query as well?
graphql/e2e/normal/script.js, line 19 at r1 (raw file):
async function newAuthor({args, graphql}) { // lets give every new author a reputation of 3 by default const results = await graphql(`mutation {
Does this accept GraphQL variables?
graphql/schema/dgraph_schemagen_test.yml, line 614 at r1 (raw file):
input: | type User { id: ID!
Add a field with @lambda
as well
graphql/schema/schemagen.go, line 417 at r1 (raw file):
for _, f := range def.Fields { if f.Type.Name() == "ID" || hasCustomOrLambda(f) {
nice check
graphql/schema/wrappers.go, line 643 at r1 (raw file):
lambdaDirectives[typ.Name] = lambdaFieldMap // then, build a custom directive with correct semantics to be put // into custom directives map at this field
Add some comments on why we do this.
graphql/schema/wrappers.go, line 646 at r1 (raw file):
customFieldMap[field.Name] = buildCustomDirectiveForLambda(typ, field, dir, func(f *ast.FieldDefinition) bool { return lambdaFieldMap[f.Name] ||
Add some comments about these checks and why we do them.
graphql/schema/wrappers.go, line 698 at r1 (raw file):
// for fields in other types, skip the ones in body template which have a @lambda or @custom // or are not scalar for _, f := range defn.Fields {
While constructing the body, we automatically add all the fields which pass the skipInBodyTemplate check
…ambda # Conflicts: # graphql/e2e/directives/docker-compose.yml # graphql/e2e/normal/docker-compose.yml
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.
Found an existing documentation ticket in the epic.
Reviewable status: 17 of 66 files reviewed, 9 unresolved discussions (waiting on @manishrjain, @MichaelJCompton, @pawanrawal, and @vvbalaji-dgraph)
dgraph/cmd/alpha/run.go, line 201 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
lambda server that implements custom GraphQL Javascript resolvers.
Done.
graphql/e2e/common/lambda.go, line 95 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Create a bug report for this.
Done.
graphql/e2e/normal/script.js, line 7 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Can we provide variables for a DQL query as well?
Yes, updated the test.
graphql/e2e/normal/script.js, line 19 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Does this accept GraphQL variables?
Yes, updated the test.
graphql/schema/dgraph_schemagen_test.yml, line 614 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Add a field with
@lambda
as well
Done.
graphql/schema/schemagen.go, line 417 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
nice check
Done.
graphql/schema/wrappers.go, line 643 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Add some comments on why we do this.
Done.
graphql/schema/wrappers.go, line 646 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Add some comments about these checks and why we do them.
Done.
graphql/schema/wrappers.go, line 698 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
While constructing the body, we automatically add all the fields which pass the skipInBodyTemplate check
Done.
This PR adds `@lambda` directive in GraphQL, using which one can call Custom JavaScript resolvers. Now, alpha has a flag called `--graphql_lambda_url` which is used to set the URL of the lambda server. All the `@lambda` fields will be resolved through the lambda functions implemented on the given lambda server. RFC: https://discuss.dgraph.io/t/implement-custom-js-resolvers-in-graphql/9361 Lambda server: https://github.com/dgraph-io/dgraph-lambda (cherry picked from commit 2f3d7f4) # Conflicts: # graphql/e2e/common/common.go # graphql/e2e/directives/docker-compose.yml # graphql/e2e/directives/schema.graphql # graphql/e2e/normal/docker-compose.yml # graphql/e2e/normal/schema.graphql # graphql/e2e/schema/generatedSchema.graphql # graphql/schema/gqlschema.go # graphql/schema/testdata/schemagen/output/authorization.graphql # graphql/schema/testdata/schemagen/output/comments-and-descriptions.graphql # graphql/schema/testdata/schemagen/output/custom-mutation.graphql # graphql/schema/testdata/schemagen/output/custom-nested-types.graphql # graphql/schema/testdata/schemagen/output/custom-query-mixed-types.graphql # graphql/schema/testdata/schemagen/output/custom-query-not-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/custom-query-with-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/deprecated.graphql # graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql # graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql # graphql/schema/testdata/schemagen/output/field-with-id-directive.graphql # graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql # graphql/schema/testdata/schemagen/output/filter-cleanSchema-directLink.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-interface-having-directive.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-interface.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-type-having-directive.graphql # graphql/schema/testdata/schemagen/output/hasInverse.graphql # graphql/schema/testdata/schemagen/output/hasInverse_withSubscription.graphql # graphql/schema/testdata/schemagen/output/ignore-unsupported-directive.graphql # graphql/schema/testdata/schemagen/output/interface-with-dgraph-pred.graphql # graphql/schema/testdata/schemagen/output/interface-with-id-directive.graphql # graphql/schema/testdata/schemagen/output/interface-with-no-ids.graphql # graphql/schema/testdata/schemagen/output/interfaces-with-types-and-password.graphql # graphql/schema/testdata/schemagen/output/interfaces-with-types.graphql # graphql/schema/testdata/schemagen/output/no-id-field-with-searchables.graphql # graphql/schema/testdata/schemagen/output/no-id-field.graphql # graphql/schema/testdata/schemagen/output/password-type.graphql # graphql/schema/testdata/schemagen/output/searchables-references.graphql # graphql/schema/testdata/schemagen/output/searchables.graphql # graphql/schema/testdata/schemagen/output/single-type-with-enum.graphql # graphql/schema/testdata/schemagen/output/single-type.graphql # graphql/schema/testdata/schemagen/output/type-implements-multiple-interfaces.graphql # graphql/schema/testdata/schemagen/output/type-reference.graphql # graphql/schema/testdata/schemagen/output/type-with-arguments-on-field.graphql # graphql/schema/testdata/schemagen/output/type-with-custom-field-on-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/type-with-custom-fields-on-remote-type.graphql # graphql/schema/testdata/schemagen/output/type-without-orderables.graphql
This PR adds `@lambda` directive in GraphQL, using which one can call Custom JavaScript resolvers. Now, alpha has a flag called `--graphql_lambda_url` which is used to set the URL of the lambda server. All the `@lambda` fields will be resolved through the lambda functions implemented on the given lambda server. RFC: https://discuss.dgraph.io/t/implement-custom-js-resolvers-in-graphql/9361 Lambda server: https://github.com/dgraph-io/dgraph-lambda (cherry picked from commit 2f3d7f4) # Conflicts: # graphql/e2e/common/common.go # graphql/e2e/directives/docker-compose.yml # graphql/e2e/directives/schema.graphql # graphql/e2e/normal/docker-compose.yml # graphql/e2e/normal/schema.graphql # graphql/e2e/schema/generatedSchema.graphql # graphql/schema/gqlschema.go # graphql/schema/testdata/schemagen/output/authorization.graphql # graphql/schema/testdata/schemagen/output/comments-and-descriptions.graphql # graphql/schema/testdata/schemagen/output/custom-mutation.graphql # graphql/schema/testdata/schemagen/output/custom-nested-types.graphql # graphql/schema/testdata/schemagen/output/custom-query-mixed-types.graphql # graphql/schema/testdata/schemagen/output/custom-query-not-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/custom-query-with-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/deprecated.graphql # graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql # graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql # graphql/schema/testdata/schemagen/output/field-with-id-directive.graphql # graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql # graphql/schema/testdata/schemagen/output/filter-cleanSchema-directLink.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-interface-having-directive.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-interface.graphql # graphql/schema/testdata/schemagen/output/hasInverse-with-type-having-directive.graphql # graphql/schema/testdata/schemagen/output/hasInverse.graphql # graphql/schema/testdata/schemagen/output/hasInverse_withSubscription.graphql # graphql/schema/testdata/schemagen/output/ignore-unsupported-directive.graphql # graphql/schema/testdata/schemagen/output/interface-with-dgraph-pred.graphql # graphql/schema/testdata/schemagen/output/interface-with-id-directive.graphql # graphql/schema/testdata/schemagen/output/interface-with-no-ids.graphql # graphql/schema/testdata/schemagen/output/interfaces-with-types-and-password.graphql # graphql/schema/testdata/schemagen/output/interfaces-with-types.graphql # graphql/schema/testdata/schemagen/output/no-id-field-with-searchables.graphql # graphql/schema/testdata/schemagen/output/no-id-field.graphql # graphql/schema/testdata/schemagen/output/password-type.graphql # graphql/schema/testdata/schemagen/output/searchables-references.graphql # graphql/schema/testdata/schemagen/output/searchables.graphql # graphql/schema/testdata/schemagen/output/single-type-with-enum.graphql # graphql/schema/testdata/schemagen/output/single-type.graphql # graphql/schema/testdata/schemagen/output/type-implements-multiple-interfaces.graphql # graphql/schema/testdata/schemagen/output/type-reference.graphql # graphql/schema/testdata/schemagen/output/type-with-arguments-on-field.graphql # graphql/schema/testdata/schemagen/output/type-with-custom-field-on-dgraph-type.graphql # graphql/schema/testdata/schemagen/output/type-with-custom-fields-on-remote-type.graphql # graphql/schema/testdata/schemagen/output/type-without-orderables.graphql
Fixes GRAPHQL-705
This PR adds
@lambda
directive in GraphQL, using which one can call Custom JavaScript resolvers. Now, alpha has a flag called--graphql_lambda_url
which is used to set the URL of the lambda server. All the@lambda
fields will be resolved through the lambda functions implemented on the given lambda server.RFC: https://discuss.dgraph.io/t/implement-custom-js-resolvers-in-graphql/9361
Lambda server: https://github.com/dgraph-io/dgraph-lambda
This change is
Docs Preview: