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

Invalid generated code for inputs when go model field type does not match the graphql field type #663

Closed
danielvladco opened this issue Apr 4, 2019 · 3 comments
Labels
bug Something isn't working enhancement New feature or request stale

Comments

@danielvladco
Copy link
Contributor

danielvladco commented Apr 4, 2019

What happened?

Invalid go code was generated.

What did you expect?

I expect valid go code to be generated. The actual generated code is not building for the following reason:
gql/exec.go:2298:17: cannot assign []*proj.MapEntry to it.Map (type map[string]string) in multiple assignment

This is the generated go code part that is failing:

case "map":
	var err error
	it.Map, err = ec.unmarshalOMapEntry(ctx, v) // failing here
	if err != nil {
		return it, err
	}

Minimal graphql.schema and models to reproduce

--- schema.graphqls

type Query {
    foo(in: Bar): Boolean
}

input Bar {
    map: [MapEntry]
}
input MapEntry {
    key: String
    val: String
}

--- gqlgen.yaml

schema:
- schema.graphqls
exec:
  filename: exec.go
model:
  filename: models.go
models:
  Bar:
    model:
    - github.com/company/proj.Bar
  MapEntry:
    model:
    - github.com/company/proj.MapEntry

--- models.go

type Bar struct {
    Map map[string]string
}

type MapEntry struct {
    Key string
    Val string
}

I tried the same usecase with graphql type and an additional resolver was added that has as parameter Bar and returns MapEntry.

I am aware of the fact that graphql types and inputs are totally different concepts and why the generated code was broken but I think it would be very handy to have some kind of generated resolvers similar to the ones for the type or some workaround for similar usecases.
Maybe show an error at generation time?

versions

  • gqlgen version v0.8.2
  • go version 1.11
  • go modules
@vektah vektah added bug Something isn't working enhancement New feature or request labels Apr 4, 2019
@vektah
Copy link
Collaborator

vektah commented Apr 4, 2019

🤔

Yeah interesting, I've marked this as both a bug and a feature. We should strive for better error messages first to make sure its obvious how this is currently invalid.

And we should consider how to handle users supplying input transforms instead of erroring, as a feature with less urgency.

@stale
Copy link

stale bot commented Aug 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 28, 2019
@stale stale bot closed this as completed Sep 4, 2019
@frederikhors
Copy link
Collaborator

Please reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

3 participants