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.
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?
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?