Auto-fill missing mandatory field OR Give error when missing mandatory field
- Vorherrschende Sprache
- Go
- Sterne
- 10.8k
- Forks
- 1.3k
- Ø Merge
- 2 T. 36 Min.
- Gemergte PRs (30 T.)
- 26
Beschreibung
I'm running into an error after creating a stub of a new query, where most of the data is missing.
```
ApolloError: the requested element is null which the schema does not allow
```
I traced the root of the error and the problem is that a field that is mandatory in my GraphQL spec is missing from the backend resolver, but gqlgen doesn't let me know about this. To solve it I had to do this:
```go
--- a/services/hava-api/pkg/resolver/foodtracker.resolvers.go
+++ b/services/hava-api/pkg/resolver/foodtracker.resolvers.go
@@ -802,8 +802,11 @@ func (r *queryResolver) ListFavoriteFoodItems(ctx context.Context, req model.Lis
CreateTime: time.Now(),
UpdateTime: time.Now(),
FoodItem: &model.Ingredient{
- Name: "ingredients/4425770c-8f5e-4573-976d-f4b3417ca46f",
- DisplayName: pointer.Pointer("Test Food Item 1"),
+ Name: "ingredients/4425770c-8f5e-4573-976d-f4b3417ca46f",
+ DisplayName: pointer.Pointer("Test Food Item 1"),
+ Satiety: &model.SatietyData{},
+ Sweetener: &model.SweetenerData{},
+ IngredientProperties: &model.IngredientProperties{},
},
},
},
```
gqlgen should either
1. Auto-fix it by supplying a non-null zero value pointer for these fields if missing
2. Give an error when running the backend endpoint (currently the API works fine as long as you don't try to access e.g. the `sweetener` field from the frontend).
3. Same as option 2 but make it opt-in with a config flag.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.