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

gqlgen is confused when the configured model type is a string #670

Closed
MichaelMure opened this issue Apr 10, 2019 · 7 comments · Fixed by #706
Closed

gqlgen is confused when the configured model type is a string #670

MichaelMure opened this issue Apr 10, 2019 · 7 comments · Fixed by #706
Labels
bug Something isn't working v0.9 Fixed in 0.9.0

Comments

@MichaelMure
Copy link
Contributor

What happened?

In this PR for my project, there is a Label type in the schema, mapped to a Label go type, which is also a string. In this case, gqlgen is confused and return the data is if it was a scalar:

the go type:

type Label string

relevant part of the schema:

"""Label for a bug."""
type Label {
    """The name of the label."""
    name: String!
    """Color of the label."""
    color: Color!
}

query:

{
  defaultRepository {
    allBugs(first: 1) {
      nodes {
        labels {
          name
          color {
            R
            G
            B
          }
        }
      }
    }
  }
}

result:

{
  "data": {
    "defaultRepository": {
      "allBugs": {
        "nodes": [
          {
            "labels": [
              "Core",
              "RFC"
            ]
          }
        ]
      }
    }
  }
}

What did you expect?

The data should have the same shape than the query. Color should be present as well.

versions

  • gqlgen version: 0.8.3
  • go version? go1.11.6
  • dep or go modules? dep
@mathewbyrne
Copy link
Contributor

I'm not sure I understand. Why have you mapped a GraphQL object type to a Go scalar?

@MichaelMure
Copy link
Contributor Author

Because it make sense in my project. A label is no more than a string, but in go I can still attach some function on it like the color (computed from the string). Having a struct hold a string is quite ackward.

@mathewbyrne
Copy link
Contributor

Sure I understand that part. I mean why have you explicitly mapped it in gqlgen.yml? How can gqlgen know how to transform your Go string into a GraphQL object?

@MichaelMure
Copy link
Contributor Author

Sorry I forgot that part in the issue, but I mapped to the Label type, not string. I feel like that should work.

@mathewbyrne
Copy link
Contributor

Ah ok I understand your problem now, so this looks like a bug to me if it's generating you the Label resolvers, but returning the scalar value before hitting them.

@mathewbyrne mathewbyrne added the bug Something isn't working label Apr 16, 2019
@vektah
Copy link
Collaborator

vektah commented May 12, 2019

@MichaelMure could you take a look over #706 and see if you can reproduce this issue in a test?

@MichaelMure
Copy link
Contributor Author

@vektah as my initial bug report was about a mapping to a string,I tried that (https://github.com/MichaelMure/gqlgen/tree/mapping-primitive, feel free to pull).

It's failing with:

=== RUN   TestPrimitiveStringObjects
=== RUN   TestPrimitiveStringObjects/can_fetch_value
panic: 2 error(s) decoding:

* 'PrimitiveStringObject[0]' expected a map, got 'string'
* 'PrimitiveStringObject[1]' expected a map, got 'string' [recovered]
	panic: 2 error(s) decoding:

* 'PrimitiveStringObject[0]' expected a map, got 'string'
* 'PrimitiveStringObject[1]' expected a map, got 'string'

goroutine 22 [running]:
testing.tRunner.func1(0xc000126800)
	/home/michael/dev/go-1.11/src/testing/testing.go:792 +0x387
panic(0x8bfa60, 0xc00000c620)
	/home/michael/dev/go-1.11/src/runtime/panic.go:513 +0x1b9
github.com/99designs/gqlgen/client.(*Client).MustPost(0xc0000a6c60, 0x95ee0b, 0x37, 0x881ca0, 0xc0000a6ca0, 0x0, 0x0, 0x0)
	/home/michael/go/src/github.com/99designs/gqlgen/client/client.go:60 +0xae
github.com/99designs/gqlgen/codegen/testserver.TestPrimitiveStringObjects.func4(0xc000126800)
	/home/michael/go/src/github.com/99designs/gqlgen/codegen/testserver/primitive_objects_test.go:67 +0x89
testing.tRunner(0xc000126800, 0xc00008d540)
	/home/michael/dev/go-1.11/src/testing/testing.go:827 +0xbf
created by testing.(*T).Run
	/home/michael/dev/go-1.11/src/testing/testing.go:878 +0x353

Process finished with exit code 1

Let me know if I got something wrong.

@vektah vektah added the v0.9 Fixed in 0.9.0 label May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.9 Fixed in 0.9.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants