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?
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!
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
}