99designs / 99designs/gqlgen

Generation fails for structs with fields to slice pointer types

Open
#1,260 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.8k
Forks
1.3k
Avg merge
2d 36m
Merged PRs (30d)
26

Description

### What happened?

#### Compilation error
Validation after generation fails. Marshal func has *v but object method has no pointer on the object.

```Error: validation failed: packages.Load: …/graphql/generated.go:2288:40: cannot use v (variable of type *domain.AppliedDiscounts) as domain.AppliedDiscounts value in argument to ec._AppliedDiscounts```

#### Observation
For the current master version:
This happens only for the field `Discounts *AppliedDiscounts` with an pointer to slice type.
Field `Test *string` works fine.

Generation of this case worked at least in v0.9.0.

### What did you expect?

Validation after generation succeeds.

### Minimal graphql.schema and models to reproduce

```
type (
Cart struct {
Discounts *AppliedDiscounts
Test *string
}

AppliedDiscounts []string
)

func (d *AppliedDiscounts) Get() string {
return "42"
}
```

```
type Cart {
discounts: AppliedDiscounts
test: String!
}

type AppliedDiscounts {
get: String!
}
````

### versions
- gqlgen version: `master`
- go version: `1.14.1`
- dep or go modules? `go modules`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.