models:
Query:
fields:
product:
resolver: true # force a resolver to be generated
users:
resolver: true # force a resolver to be generated
// Product returns generated.ProductResolver implementation.
func (r *Resolver) Product() productResolver { return productResolver{r} }
// User returns generated.UserResolver implementation.
func (r *Resolver) User() userResolver { return userResolver{r} }
type productResolver struct{ *Resolver }
type userResolver struct{ *Resolver }
models
gqlgen.yaml. I want to reference the models generated by protobuf, so that I can easily pass the result from the GRPC client. The examples are reassigning to the generated model manually, my types are larger, so it would be very much boilerplate. However, when I try to set the models in the configuration file, gqlgen
command generates resolvers for all nested structs. How do avoid it? I haven't been able to turn them off, is there a trick?
filename_template
key to set the resolver name in config file config
Hi there.
I have a validate
directive directive @validate(rule: String!) on INPUT_FIELD_DEFINITION
.
and the directive implemention:
func validateDirective(ctx context.Context, obj interface{}, next graphql.Resolver, rule string) (res interface{}, err error) {
res, err = next(ctx)
if verr := validate.Var(res, rule); verr != nil {
return nil, verr
}
return res, nil
}
Hi, I'm new here...
We currently have a graphQL server running in NodeJS and Apollo Server making use of authentication outside of the GraphQL layer. Rather than doing any authentication or authorization work in the GraphQL layer (in resolvers/models), it’s possible to simply pass through the headers or cookies to your REST endpoint and let it do the work.
// src/server.js
context: ({ req }) => {
// pass the request information through to the model
return {
user,
models: {
User: generateUserModel({ req }),
...
}
};
},
// src/models/user.js
export const generateUserModel = ({ req }) => ({
getAll: () => {
return fetch('http://myurl.com/users', { headers: req.headers });
},
});
Would something like this be possible with gqlgen and resolvers using gRPC (instead of REST)?
// Defining mutation function
func mutateHook(b *modelgen.ModelBuild) *modelgen.ModelBuild {
for _, model := range b.Models {
for _, field := range model.Fields {
field.Tag += ` orm_binding:"` + model.Name + `.` + field.Name + `"`
}
model.Fields = append(model.Fields, &modelgen.Field{
Description: "ex",
Name: "ex",
Type: model.Fields[0].Type,
})
}
return b
}
How to efficiently implement broadcasting?
I have a Subscription that emits a new value every second. Multiple (100+) clients are subscribed to it using the same exact query.
Does gqlgen cache similar queries? If not, is it possible to have single resolver / executor / marshaler rather than one per subscribed client?
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
}
gqlgen.yaml
:models:
DateTime:
model: github.com/MyOrg/MyRepo/internal/backend/gql/gqlresolvers.DateTime
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 ;-)
{"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 !!!
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.
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.