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

fix(GRAPHQL): Add error handling for unrecognized args to generate directive. #7612

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/dgraph-io/badger/v3 v3.0.0-20210309075542-2245c18dfd1f
github.com/dgraph-io/dgo/v200 v200.0.0-20210212152539-e0a5bde40ba2
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.1.9
github.com/dgraph-io/gqlparser/v2 v2.2.0
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed
github.com/dgraph-io/ristretto v0.0.4-0.20210310100713-a4346e5d1f90
github.com/dgraph-io/simdjson-go v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ github.com/dgraph-io/dgo/v200 v200.0.0-20210212152539-e0a5bde40ba2/go.mod h1:zCf
github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM=
github.com/dgraph-io/gqlgen v0.13.2/go.mod h1:iCOrOv9lngN7KAo+jMgvUPVDlYHdf7qDwsTkQby2Sis=
github.com/dgraph-io/gqlparser/v2 v2.1.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/gqlparser/v2 v2.1.9 h1:rLmGvSY3ZAmHZEWHuus6CrXBLF2Ggdkg+Wu7niqAOUA=
github.com/dgraph-io/gqlparser/v2 v2.1.9/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/gqlparser/v2 v2.2.0 h1:fKSCW8OxoMogjDwUhO9OrFvrgIA0UZspTDbcm0QGk9M=
github.com/dgraph-io/gqlparser/v2 v2.2.0/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed h1:pgGMBoTtFhR+xkyzINaToLYRurHn+6pxMYffIGmmEPc=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210223074046-e5b8b80bb4ed/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ=
github.com/dgraph-io/ristretto v0.0.4-0.20210309073149-3836124cdc5a/go.mod h1:MIonLggsKgZLUSt414ExgwNtlOL5MuEoAJP514mwGe8=
Expand Down
1 change: 0 additions & 1 deletion graphql/resolve/mutation_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,6 @@ func copyTypeMap(from, to map[string]schema.Type) {
}

func extractVal(xidVal interface{}, xidName, typeName string) (string, error) {
fmt.Println(typeName)
switch typeName {
case "Int":
switch xVal := xidVal.(type) {
Expand Down
8 changes: 3 additions & 5 deletions graphql/schema/gqlschema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -999,12 +999,11 @@ invalid_schemas:
}

type Query {
getAuthor1(id: ID): Author! @custom(http: {url: "blah.com", method: "GET"}, extra: "random")
getAuthor1(id: ID): Author! @custom(http: {url: "blah.com", method: "GET"}, dql: "random")
}
errlist: [
{"message": "Type Query; Field getAuthor1: has 2 arguments for @custom directive, it should contain exactly one of `http` or `dql` arguments.",
"locations":[{"line":7, "column":32}]},
{"message" : "Type Query; Field getAuthor1; url field inside @custom directive is invalid.", "locations" : [{"line":7, "column":52}]}
]

- name: "@custom directive without http or dql argument"
Expand All @@ -1018,7 +1017,7 @@ invalid_schemas:
getAuthor1(id: ID): Author! @custom(https: {url: "blah.com", method: "GET"})
}
errlist: [
{"message": "Type Query; Field getAuthor1: one of `http` or `dql` arguments must be present for @custom directive.",
{"message": "https is not supported as an argument for custom directive.",
"locations":[{"line":7, "column":32}]},
]

Expand Down Expand Up @@ -2865,14 +2864,13 @@ invalid_schemas:

- name: "@lambdaOnMutate with bad arg values"
input: |
type TwitterUser @lambdaOnMutate(add: true, update: badValue, delete: "false", badArg: true) {
type TwitterUser @lambdaOnMutate(add: true, update: badValue, delete: "false") {
id: ID!
name: String
}
errlist: [
{ "message": "Type TwitterUser; update argument in @lambdaOnMutate directive can only be true/false, found: `badValue`.", "locations": [{"line": 1, "column": 45}]},
{ "message": "Type TwitterUser; delete argument in @lambdaOnMutate directive can only be true/false, found: `\"false\"`.", "locations": [{"line": 1, "column": 63}]},
{ "message": "Type TwitterUser; @lambdaOnMutate directive doesn't support argument named: `badArg`.", "locations": [{"line": 1, "column": 80}]}
]

- name: "@lambdaOnMutate isn't allowed on @remote types"
Expand Down
13 changes: 0 additions & 13 deletions graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,19 +1270,6 @@ func lambdaOnMutateValidation(sch *ast.Schema, typ *ast.Definition) gqlerror.Lis
}

for _, arg := range dir.Arguments {
switch arg.Name {
case "add":
case "update":
case "delete":
// do nothing
default:
errs = append(errs, gqlerror.ErrorPosf(
arg.Position,
"Type %s; @lambdaOnMutate directive doesn't support argument named: `%s`.",
typ.Name, arg.Name))
continue // to next arg
}

// validate add/update/delete args
if arg.Value.Kind != ast.BooleanValue {
errs = append(errs, gqlerror.ErrorPosf(
Expand Down