Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 23:05
    duckbrain synchronize #1652
  • 23:01
    duckbrain synchronize #1652
  • 22:39
    StevenACoffman commented #1652
  • 20:24
    jdoklovic opened #1668
  • 20:11
    duckbrain synchronize #1652
  • 15:48
    JohnMaguire opened #1667
  • 14:37
    coveralls commented #1666
  • 14:18
    JohnMaguire opened #1666
  • 07:44
    uid-one commented #1483
  • 07:27
    frederikhors commented #1664
  • 07:26
    HuanLiu-hotstar commented #1553
  • 07:06
    ss-ravi opened #1665
  • 06:15
    lwc labeled #1651
  • 06:15
    lwc labeled #1651
  • 06:15
    lwc labeled #1662
  • 06:15
    lwc labeled #1662
  • 06:14
    lwc labeled #1662
  • 06:13
    lwc labeled #1664
  • 06:11
    lwc labeled #1664
  • 06:10
    lwc labeled #1664
Erik Müller
@asterikx
(I'm doing a POST)
I using Chi for routing:
func NewRouter(r *chi.Mux, h http2.AppHandler, j *jwtauth.JwtAuth) *chi.Mux {
    r.Use(middleware.RequestID)
    r.Use(jwtauth.Verifier(j))
    r.Route("/graphql", func(r chi.Router) {
        r.Handle("/", playground.Handler("GraphQL playground", "/query"))
        r.HandleFunc("/query", h.GraphQL.Handle)
    })
    return r
}
Erik Müller
@asterikx
Ah, think I found the issue, I was creating my sever using the New func (which does not add any "protocols") instead of the NewDefaultServer func (which adds a bunch of default "protocols")
Kfir Ozer
@kfirufk
can anyone provide information about the status of custom struct tags ? (99designs/gqlgen#1173) I want the types that I define will have "db":value with same value of the json hinting in order for sqlx to work with it properly
Kfir Ozer
@kfirufk
never mind i implemented it using https://gqlgen.com/recipes/modelgen-hook/
Jonatan Magnusson
@jomag_gitlab
Hey! I'm trying to add a simple custom DateTime scalar that uses RFC3339 to serialize to/from string. type DateTime time.Time.
All is fine, except I can't get gqlgen to find the type!
I have this in gqlgen.yaml:
models:
  DateTime:
    model: github.com/MyOrg/MyRepo/internal/backend/gql/gqlresolvers.DateTime
Jonatan Magnusson
@jomag_gitlab
Oh never mind! Found it: my problem was that the folder containing package "gqlresolvers" was called "resolvers".
Jonatan Magnusson
@jomag_gitlab
One thing I'm not quite sure how to handle is how data could/should be passed on to nested resolvers:
Project I'm working on has some model types, that are not the same as the model types generated by gqlgen. They are typically quite similar though, and I use mappers to translate them back and forth.
When a nested, custom resolver (let's say the User model has Cars) is called, the gqlgen generated User model will be passed to the resolver. But what if I need access to the non-generated model?
Jonatan Magnusson
@jomag_gitlab
In my case, the models reflect a postgres database table, and I can use the ID in the generated User type to fetch the user from database again in the resolver, but I don't want to fetch the same user more than once in a single query. Should I rely on data loader in that case? Or should I pass the user in context or Resolver type?
Samuel Suter
@moensch
Hey all! I wonder if someone is available to talk through this issue? 99designs/gqlgen#1256
In short: type System gets used when federation is enabled, meaning, we cannot have a type of the same name in our schema anymore. Thankfully, we're still at the inception stage of our project, so we can still adjust our schema without external impact. Though I'd love to be able to have a System type in my own schema ;-)
Tassios Marios
@mariosttass
Hello guys, I have a question regarding the error logging of the handler. Basically when I am sending a POST request to the server without specifying the content type I am receiving this error {"errors":[{"message":"transport not supported"}],"data":null} which is totally fine. What I need is to log that error, can you please give me an idea about that ? Thank a lot !!!
Farhan Syed
@Nearhan

Hi there guys. I have a question regarding plugins and custom resolvers, and the best way to use them.
I came up with a really convuluted solution and I think I made a wrong turn.

For some background info.

  • We are using graphql to basically wire up all our micro services
  • All these microservices use protobuff for their service layer which means we have awesome gerneated code for that
  • We would love to reuse those generated models to be our models for graphql
  • So we wrote a tool to take proto files and turn them into a graphql spec.
  • We also are utilizing autobind feature so that we can point graphql models to the protobuff ones

Of course things don't overlap.

Enums in graphql are strings
Enums in protobuff are int32

Cool we should be able to write a custom resolver for this since the code to do this dead simple and we have TON of enums. We would like to reduce how much code humans need to write.

So I tried writing a plugin.
I realized that all i really wanted to do was basically modify this line https://github.com/99designs/gqlgen/blob/master/plugin/resolvergen/resolver.go#L108 ; and just write an implementation for specifc types.

However for me to do this. I had to copy the entire resolvergen plugin and just modify those few lines. I copied this becuase of this issue 99designs/gqlgen#1058.

Is this still the only way to do this? Anything I really got wrong here?
I'd love just to beable to do this in a much smaller footprint.

Chethan C
@chethanphoenix

Hey,

I am making a call to graphql web endpoint {{url}}/query with the below graphql query from postman

query getWarGames {
  warGames {
    id
    trigger
    status
  }
}

but I am getting floowing error

{
    "errors": [
        {
            "message": "operation  not found"
        }
    ],
    "data": null
}

Any idea what could be the issue?

Jonatan Magnusson
@jomag_gitlab
Hey! I've built a middleware that put the session user id in Context. In my resolvers, I can then get that user id from context, fetch the user, and check the users permission based on role and other things.
Now problem is: I don't want to fetch the user from database in every resolver that needs to check authorization.
Before I wrapped my head around the problem, I was thinking I could put the user model in the context as well. But that would actually require that I mutate the context, which of course does not work.
So now I'm down to two options: use data loader or always fetch the user in the middleware, even if it's not required. Does that sound right, or is there any other option I'm missing?
Jonatan Magnusson
@jomag_gitlab
Just thought of a third option: if I extend the generated type with an extra "current user" field, then all sub-resolvers can get the user from there. But that would require that I don't autogenerate the type, moving further and further from the "schema first" philosophy...
Jonatan Magnusson
@jomag_gitlab
Similar question: I have a allUsers query that returns a UsersConnection type that has among other things a users field. As not every query will require the users field I don't want to fetch users from db in the allUsers resolver. Instead I have a custom resolver for UsersConnection.users. But allUsers has some pagination arguments that the users resolver need access to. So how can I do that? One option is to once again extend the UsersConnection type with pagination data. Does that sound right to you?
Philipp Kraus
@flashpixx

Hello I'm new with gqlgen and I try to create a mutation with this definition:

activityConfiguration(activity: String!): ActivityConfiguration!

But I don't know how I can create the "models:" sections for this entry in my gqlgen.yml? Thanks for help

yuvalt7
@yuvalt7
Is it possible to modify the context inside of a resolver? I'm aware of the gin's recipe and using a middleware, but can we do it in a resolver itself, which will affect other resolvers that will run later?
Jonathan Duck
@duckbrain_gitlab
@yuvalt7 I don't think you can with GQLGen's interface. The best option is probably put something mutable in the context (before passing it to GQLGen) and update that. As a hack, you could also make a mutable context you pass to GQLGen, but that would break context.Context's contract.
yuvalt7
@yuvalt7
@duckbrain_gitlab thanks, using a mutable object in the context sounded like an anti-pattern to me and I wanted to know if there was a more main-stream way
but guess not :(
Clio Harper
@clio.harper_gitlab

Hi all! I recently discovered this project and think it's fantastic. I'm currently making a bid to get my company to switch over to Go for some of our services. As a proof of concept, I'm moving our most basic service over and came across a small issue porting the code from typescript. In our TS implementation, our directive overwrites one of the graphql arguments if the user has a certain role. Both the userId and role are set by a gateway that sits in front of all our services:

      if (roles.includes(subject.headers.role)) {
        methodArgs.userId = subject.headers['user-id'];
      }
     ...
     return resolver(parent, methodArgs, context, ...rest);

In Go, I can get the args like so: graphql.GetResolverContext(ctx).Args but I can't seem to find a way to reassign them in my directive implementation.

Any insight would be appreciated. Thanks!

r33drichards
@r33drichards
I'm struggling to understand how I'd pass a dynamodb connection to a resolver in gqlgen.
I'm actually at a lost at how it works in postgres as well.
I'm looking at a reference implementation and theres a connection being passed to a resolver here https://github.com/oshalygin/gqlgen-pg-todo-example/blob/master/resolvers/resolver.go#L9 but there doesn't seem to be a way that that connection knows the database name, or user or password to the database? It just seems to me that there is a pointer to something that doesn't exist.
its gotta be something like this ?
package graph

//go:generate go run github.com/99designs/gqlgen

import (
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/dynamodb"
)

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.

var sess = session.Must(session.NewSession())
var svc = dynamodb.New(sess)

type Resolver struct {
    svc *dynamodb.DynamoDB
}
r33drichards
@r33drichards
okay I see how it happens now
Alexey Yurchenko
@alexesDev
Hi. Why I cannot add fields with Query type? type Query { api: Query! } or type Mutation { doSome: Query! }. It produces an error but works in graphql-js
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x7ae2df]

goroutine 1 [running]:
github.com/99designs/gqlgen/codegen/config.(*TypeReference).IsPtr(...)
/home/alexes/go/pkg/mod/github.com/99designs/gqlgen@v0.11.3/codegen/config/binder.go:204
Bogdan Stănescu
@bstanescu

Hi all. Is there a way to get the client's IP address for subscriptions?

It's fairly easy for queries/mutations via HTTP transport (by using a middleware similar to the authentication mechanism).
I'm not sure I can access the websocket client's IP address, and InitPayload does not contain such information

bonafideyan
@bonafideyan
I define a union type, gqlgen help me generate its interface, but not for implementation of the union type's member type, where am I wrong
it generated a model implementation for the union, that is a interface in golang, but I need the union memeber type has the method defined by the interface
Joana Roque
@rokjoana
hello! just wanted to ask if the project is still being maintained and what are the steps one can do to contribute :) the readme just points to this gitter room. I read in an issue that someone requested access to github discussions but there's no link anywhere
Bruno Martinez
@brunomartinez-lmi
Hello,
I found an issue with the default recovery (func DefaultRecover) in combination with the default ErrorPresenter(DefaultErrorPresenter).
This cause a second panic while recovering from the first one due to a cast error.
I could propose a fix, what are the step to be allowed to contribute or to make a PR ?
Jonatan Magnusson
@jomag
Hi! I have implemented some subscriptions, and today found a problem: I have subscriptions for bookings and each booking have a nested User. If I request the booking including the user with a normal query, everything works as expected. But if I use the same subfields for a subscription, user is always null.
Is this expected behavior?
I have a custom resolver for Booking.user, which does not seem to be called for subscriptions, but works as expected for queries and mutations.
Nhan Thai
@dandoh
Hi, seems like if I add the directive @goField(forceResolver: true) to a field, gqlgen generates both the resolver and the field inside Go struct. What do I do if I only want the resolver?
For example:
extend type Admin {
    user: User! @goField(forceResolver: true)
}
then I got both
func (r *adminResolver) User(ctx context.Context, obj *model.Admin) (*model.User, error) {
    panic(fmt.Errorf("not implemented"))
}
and
type Admin struct {
    ...
    User      *User     `json:"user"` <-- I don't want this
}