99designs / 99designs/gqlgen

Weak type validation?

Offen
#1,522 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Go
Sterne
10.8k
Forks
1.3k
Ø Merge
2 T. 36 Min.
Gemergte PRs (30 T.)
26

Beschreibung

### What happened?
The GraphQL type definition is not being respected.
In the definition we force the quantity to be an integer. However, the consumer of the API can bypass that validation by passing a string. The gqlgen library will try to parse it internaly anyway.

### What did you expect?
We expect that gqlgen respects the definition and returns a `GRAPHQL_VALIDATION_FAILED` error code in case the consumer passes an invalid type, which in this case is a string instead of an integer.

### Minimal graphql.schema and models to reproduce
```
updateItems(
"A list of item data."
items: [UpdateItemInput!]!

"Language code (two-letter code: ISO 639-1)."
languageCode: String
): Cart

input UpdateItemInput {
"The item number."
itemNo: ID!

"The item quantity."
quantity: Int!
}
```

```
curl --request POST \
--url https://app.com/graphql \
--data '{"query":"\n mutation UpdateItems(\n $items: [UpdateItemInput!]!\n $languageCode: String\n ) {\n updateItems(items: $items, languageCode: $languageCode) {\n items {\n quantity\n }\n }\n }\n ","variables":{"items":[{"itemNo":"12345678","quantity":"test"}],"languageCode":"cs"},"operationName":"UpdateItems"}'
```

### versions
- `gqlgen version 1.15`
- `go version 0.13.0`?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.