Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 00:18
    droslean edited #2395
  • 00:18
    droslean commented #2395
  • 00:17
    droslean opened #2395
  • Sep 27 23:59
    droslean edited #2394
  • Sep 27 23:59
    droslean opened #2394
  • Sep 26 13:56
    droslean commented #2360
  • Sep 26 12:30
    StevenACoffman commented #2360
  • Sep 26 11:05
    droslean commented #2360
  • Sep 26 11:04
    droslean commented #2360
  • Sep 26 10:46
    droslean commented #2360
  • Sep 26 10:42
    droslean commented #2360
  • Sep 26 06:37
    CaptainNickSilver commented #2345
  • Sep 26 04:44
    rentiansheng commented #2391
  • Sep 25 07:19
    rafaelvanoni opened #2393
  • Sep 25 00:08
    Unkn0wnCat commented #953
  • Sep 24 19:42
    kateile commented #953
  • Sep 24 15:54
    jakezhu9 commented #2367
  • Sep 24 13:58
    jakezhu9 commented #2360
  • Sep 23 15:08
    nullism opened #2392
  • Sep 23 11:29
    StevenACoffman commented #2391
Muhammad
@harmnot
when I do go mod , it list the packages
Adam Scarr
@vektah
are any of your imports relative?
eg
import (
    "./subdir"
)
Muhammad
@harmnot
yes, I am using goland
I think I need to recreate project on gopath
Adam Scarr
@vektah
no dont do that
image.png
you probably just need to click this box
but definitly dont use relative imports
going back to gopath will break dependency pinning, so you dont want that either
Muhammad
@harmnot
did u meant uncheck?
Adam Scarr
@vektah
it should be turned on
Muhammad
@harmnot
it was
Adam Scarr
@vektah
with it turned on and all relative imports turned to absolute ones you should be fine
"./subdir" -> "graph/subdir"
Muhammad
@harmnot
it was like that, getting red error now after some change :)
Jakub Sobieraj
@sobiso_gitlab
how i can add opentracing to gqlgen ?
Ara Bruno
@error-bruno
Sorry if this has been answered/asked. And maybe it's not possible to use proto file, but I have a proto file, that my project can use, but when I try to use that proto file in gqlgen.yml it errors out with merging type systems failed: unable to build object definition: unable to find type path/to/proto.SearchResponse
Adam Scarr
@vektah
Check that you have an import path, not a file path
Like it would be if you imported it
Ara Bruno
@error-bruno
Like I would import it into a a go file, correct?
Adam Scarr
@vektah
Yeah
Ara Bruno
@error-bruno
Yeah, that's what I'm using. I'm able to use that import path in my go code, where my GO package can read it, but that same import path won't work in gqlgen.yaml
Adam Scarr
@vektah
That's how it should work. There's nothing special about proto (we use it, it works fine)
Does go list that/path work inside the project dir?
This using modules right?
Jimmy
@kejiro

@ethanrubio

You get it from the ID. According to the spec, the id is a global identifier, and using the id would guarantee that the same object always gets returned. So matching it on __typename would probably be breaking the relay spec.

I solved it like this:

func (r *queryResolver) Node(ctx context.Context, globalId string) (Node, error) {
    loaders := tenants.LoadersFromContext(ctx)
    nodeType, id, err := fromGlobalId(globalId)
    if err != nil {
        return nil, err
    }
    switch nodeType {
    case "User":
        return loaders.User().Load(id)
    case "Organization":
        return loaders.Organization().Load(id)
    case "Group":
        return loaders.Group().Load(id)
    default:
        return nil, fmt.Errorf("type not supported: %s", nodeType)
    }
}
var globalIdSeparator = ":"

func toGlobalId(typeName string, id primitive.ObjectID) string {
    return base64.StdEncoding.EncodeToString([]byte(typeName + globalIdSeparator + id.Hex()))
}

func fromGlobalId(globalId string) (typeName string, id primitive.ObjectID, err error) {
    decoded, err := base64.StdEncoding.DecodeString(globalId)
    if err != nil {
        return "", primitive.NilObjectID, nil
    }
    ids := strings.Split(string(decoded), globalIdSeparator)
    if len(ids) != 2 {
        return "", primitive.NilObjectID, fmt.Errorf("invalid global id format")
    }
    typeName = ids[0]
    id, err = primitive.ObjectIDFromHex(ids[1])
    return
}

Of course, that requires a resolver for each ID in all models.
It would probably be nice if it was possible to create a generic ID resolver/marshaller that gets the entire model and not just the field value (to be able to get the model type), not sure if that's possible.

Adam Scarr
@vektah
Nice @kejiro , That was my understanding too but reading through the docs I cant find any explicit reference to any of this
https://facebook.github.io/relay/graphql/objectidentification.htm is almost trying to give the wrong impression
Jimmy
@kejiro

@vektah, it does say so in that document:

"This id should be a globally unique identifier for this object, and given just this id, the server should be able to refetch the object."
"If a query returns an object that implements Node, then this root field should refetch the identical object when value returned by the server in the Node‘s id field is passed as the id parameter to the node root field."

It doesn't explicitly say that it needs to identify the type, but it needs to be globally unique, so where would be a better way to put it, and also guarantee global uniqueness, especially if using a regular db and primary keys :)
And, if I recall correctly, that is how the relay package for js does ;)

Adam Scarr
@vektah
yeah, i know but you've got to read between the lines so much to figure out whats going on
Jimmy
@kejiro
well, it is documentation. At least they got lines to read between, compared to other projects :D
Adam Scarr
@vektah
:D
I cant help but feel like thats a dig at the gqlgen docs. Doc writing is hard, its a whole different skillset for sure
and unlike code/tests, they dont break when they fall out of date
Jimmy
@kejiro
:) No, not really, haven't had any major issues with those docs, but a lot of, especially javascript and java, packages it's easier to read the code to see what something does than try to get it from the docs.
But it's true, documentation is not easy, I can't say that I'm very good at it either. But with godoc and it's documentation so close to the code at least it's easier than a completely separate document, even it's not perfect.
Adam Scarr
@vektah
yeah, go is the perfect language for jump-to-definition
which means theres no place better for your docs
Muhammad
@harmnot
did u know why I can't go list ? because my main package was another folder ,
@vektah
g
@SimplyKnownAsG

Hi I'm looking to use the feature introduced in 99designs/gqlgen#375. I am forced to use a single version of mapstucture (the latest) and it has caused errors in slices_test.go. gqlgen is on an older version, upgrading mapstructure in gqlgen will break the tests. The code asserts Test1 []string and Test3 []*string should resolve to nil and [] respectively. The newer version of mapstructure will return nil for all or [] for all depending on the value of ZeroFields.

Does this test have anything to do with the feature (always use pointers in resolver return types)? Do you know what errors having the different versions might cause?

Adam Scarr
@vektah
375 shouldnt affect that
Adam Scarr
@vektah
with json encoding an empty slice becomes [] and a nil becomes null, gqlgen does some magic on top for fields that are [Foo]!, as null doesnt make sense for them, so they always return [] regardless
as far as inputs go, it doesnt matter, a nil slice is len() == 0
g
@SimplyKnownAsG
where does gqlgen do something on top for non-null fields? I do not see that in client/client.go
Adam Scarr
@vektah
in the generated code
client is just used for testing