Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 03:48
    carldunham commented #2333
  • 01:50
    AdamJSoftware opened #2333
  • Aug 19 23:46
    neptoess commented #2332
  • Aug 19 15:16
    neptoess commented #2332
  • Aug 19 15:13
    coveralls commented #2332
  • Aug 19 15:13
    coveralls commented #2332
  • Aug 19 15:10
    neptoess synchronize #2332
  • Aug 19 15:08
    coveralls commented #2332
  • Aug 19 15:05
    neptoess opened #2332
  • Aug 19 13:30
    neptoess commented #2331
  • Aug 19 13:21
    neptoess commented #2331
  • Aug 19 11:45
    StevenACoffman commented #2314
  • Aug 19 11:44
    StevenACoffman commented #2331
  • Aug 19 11:42
    StevenACoffman closed #2327
  • Aug 19 11:42
    StevenACoffman commented #2327
  • Aug 19 11:41
    StevenACoffman closed #2330
  • Aug 19 08:36
    argoyle commented #2331
  • Aug 19 08:26
    argoyle opened #2331
  • Aug 18 21:07
    coveralls commented #2330
  • Aug 18 21:04
    dcarbone edited #2330
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
g
@SimplyKnownAsG
Thanks for that. I'll have to look into it to better understand. in that case, is the error during testing when upgrading mapstructure a false positive?
g
@SimplyKnownAsG
If I wanted to do a PR to update mapstructure, should I change the test or change the client?
Adam Scarr
@vektah
First I would check that the raw json from gqlgen isn't changing, then make the test work whichever way matches closest to the json representation
My biggest concern is going to be around peoples internal uses of mapstructure, as a version bump (unless they did a major) will also push along all other uses
Ethaniel Rubio
@ethanrubio
i'm trying to understand the dataloaden library and how to best utilize it. i find my users via an external API, so I can query for them directly by userID but in the examples of dataloaden, all the users are loaded in instead. should I be following this pattern using this external API? it allows for searching of all users in a similar manner, but that seems a little weird to me when I just want to cache the api response so that it can be reused in child resolvers similar to how it's done here https://graphql.org/blog/rest-api-graphql-wrapper/.
Adam Scarr
@vektah
That's one of the jobs of the dataloader, it's assuming that a batch fetch I'd much cheaper. If your API can't do batch your probably better off with a simple cache instead
Sven Roeterdink
@swennemans
Is there any documentation/examples about logging? I'm trying to log both graphql errors but also server errors (for example: database errors). Or is the default using the ApolloTracer?
Alireza Salary M.N
@arsmn
Is it possible to access field collection for input object?
Kirill Tatchihin
@rbUUbr
hi there! I want to measure time duration for each field's resolving. Is there some builtin ways to do it?
Adam Scarr
@vektah
@swennemans take a look at AroundFields on the handler - https://gqlgen.com/recipes/migration-0.11/
@rbUUbr same to you
@arsmn no, inputs dont get collected. thats part of the response (output type, not input type) handling - see http://spec.graphql.org/June2018/#sec-Field-Collection
Kirill Tatchihin
@rbUUbr
@vektah great, thanks! updated version, really great updates, now handler looks pretty and without a lot of methods
Julien
@juleur
hi all, does something change about errors since 0.11 ? I cant return Extensions custom errors anymore
Bhaskar Saraogi
@bhaskarsaraogi_twitter
Hi, trying to find how to define a custom JSON scalar in gqlgen(something on the lines of, https://github.com/taion/graphql-type-json) ?
scalar Map doesnt work exactly, becuase marshalling primitve json like 0 or "some string" fails
Adam Scarr
@vektah
@bhaskarsaraogi_twitter are you looking for Any?
@juleur lots of things changed, if you have a more concrete example I can take a look
Julien
@juleur
now, its returning the message only (extensions are left out)
Julien
@juleur
?
Andreas Backx
@AndreasBackx
Does anyone know whether the context from the federated gateway is propagated in gqlgen? I cannot find any documentation on it and following what a request goes through is a bit hard. https://www.apollographql.com/docs/apollo-server/federation/implementing/#sharing-context-across-services
Andreas Backx
@AndreasBackx
Oh wow, I looked straight over the fact that you need to do that manually. My apologies.