99designs / 99designs/gqlgen

Resolver chaining With gqlgen, mongoDB, and Apollo

Abierto
#2,695 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Go
Estrellas
10.8k
Forks
1.3k
Merge medio
2 d 36 min
PR fusionados (30 d)
26

Descripción

### What happened?
I'm unable to figure out how to chain resolvers with mongoDB.
### What did you expect?
I am expecting to be able to chain resolvers for queries with mongoDB ID's and Apollo's federation. In the Mongo data base `Application` has a resources field is an array of [ObjectID's] to `Resources` Documents. but I run into an issue when trying to resolve the application document.
```
error decoding key resources.0: cannot decode objectID into a model.Resource
```

I've tried creating a explicit resolver using
```
Application:
fields:
resources:
resolver: true
```

However this creates a separate applicationResolver upon generation that's never called when trying to do my queryResolver for Application. I feel like there should be some clean way to have this work. IE Get the Application, using the Application's resource field (a list of Resource ObjectIDs) get an array of resources. return a application with a resource struct and not a ID.


### Minimal graphql.schema and models to reproduce
schema
```
type Application @key(fields: "_id") {
_id: ID!
text: String!
resources: [Resource!]!
}

type Resource @key(fields: "_id") {
_id: ID!
text: String!
link: String!
}

type Query {
applications: [Application!]!
}
```

models generated by gqlgen (I'll ad a `bson:` field tag as well.)
```
type Application struct {
ID string `json:"_id"`
Text string `json:"text"`
Resources []*Resource `json:"resources"`
}

type Resource struct {
ID string `json:"_id"`
Text string `json:"text"`
Link string `json:"link"`
}
```
### versions
- v0.17.33
- go version go1.20.1 darwin/amd64

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.